function saveas output format (how to save a plot in for loop and specific location)
Show older comments
Hi Everyone,
I'm having difficulties with 'saveas' function. This is the only output format I can find:
saveas(H,'FILENAME','FORMAT')
I am looking for an example output format for this function for how to add a changing file name (for each for loop iteration) and how to add location (where I want the files to be saved).
My question:
I have the following command (taken from an inside of a for loop):
hist_pat=figure
histogram(log_band_power) %matrix of 114x5 data
title(strcat('logged-data '+ currentSubject + ' parc60')); %plot title changes with each loop; different patient
saveas(hist_pat, '') % hist_pat is the plot I want to save, '' is for the name of the plot; the problem
...where should I add the following to the [saveas (hist_pat, '')] line of code:
changing name and location: (strcat(dataLoc, 'log_check/log_histogram', currentSubject, 'log.svg'),'hist_pat')
I know the layout will be differnet of the line above, but I can't find any examples online on how to structure that line of code.
Any suggestions?
Thank You!
Answers (1)
Vyte Jan
on 20 Sep 2022
0 votes
3 Comments
Stephen23
on 20 Sep 2022
Rather than squeezing everything onto one line, using two lines makes the code intent much clearer:
fnm = strcat(dataLoc, 'log_check_patient_60/log_histogram/', currentSubject, '.fig')
saveas(gca,fnm);
You should also learn about SPRINTF and FULLFILE.
Vyte Jan
on 20 Sep 2022
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!