Filter löschen
Filter löschen

save output of a code within the code?

3 Ansichten (letzte 30 Tage)
Victoria Klimaj
Victoria Klimaj am 11 Okt. 2013
Kommentiert: Victoria Klimaj am 13 Okt. 2013
Hi,
I am using a script to generate a plot/figure based on a numbers in text file. I am able to generate the figure, however, I would like to include a command at the end of the script for this output to be saved with the name "figure" in the same directory that the input was taken from. Any simple way to do this? (note--The input will be selected by hand every time via "spm_select").
The code is below:
rp = spm_load(spm_select);
figure;
subplot(2,1,1);plot(rp(:,1:3));
set(gca,'xlim',[0 size(rp,1)+1]);
subplot(2,1,2);plot(rp(:,4:6));
set(gca,'xlim',[0 size(rp,1)+1]);
Thanks!
Victoria

Akzeptierte Antwort

David Sanchez
David Sanchez am 11 Okt. 2013
First, add a handle to the figure, then, use saveas:
rp = spm_load(spm_select);
h = figure;
subplot(2,1,1);plot(rp(:,1:3));
set(gca,'xlim',[0 size(rp,1)+1]);
subplot(2,1,2);plot(rp(:,4:6));
set(gca,'xlim',[0 size(rp,1)+1]);
my_saving_dir = 'C:\whatever'; % this is the folder to save to
my_file_name = 'file_name.fig'; % feel free to choose another extension
saving_name = strcat(my_saving_dir,my_file_name);
saveas(h,saving_name)
  1 Kommentar
Victoria Klimaj
Victoria Klimaj am 13 Okt. 2013
Thank you! That was very helpful and worked perfectly. Unfortunately now I am having trouble using this within a for-loop to handle multiple subjects at once--for some reason Matlab doesn't like the "saveas" within a loop, or the figure commands--but am much closer now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by