Borrar filtros
Borrar filtros

saving a figure within a loop

1 visualización (últimos 30 días)
Victoria Klimaj
Victoria Klimaj el 13 de Oct. de 2013
Comentada: Victoria Klimaj el 14 de Oct. de 2013
Hi,
I am trying to use the script below to generate a figure based on a text files for each one of 155 subject folders. The for loop is meant to change the subject folder every time and then generate the figure based on the text file located within it and then save the output in the same subject folder.
For some reason I am getting "index exceeds matrix dimension" errors on the lines that start with "subplot" when I try to run this in a for loop (though this portion of the script works fine when it is just handling one subject outside a loop), as well as an "invalid handle" error while evaluating the "saveas" line. Any thoughts on how I could make it work? (a note--the subject folders are specified in the Order.mat file)
Thanks! -Victoria
%%%%%
nsubj=155
location='/Volumes/USB_AIB/MOVr1unzipDONE'
load /Volumes/USB_AIB/Order.mat
for csubj=1:nsubj
rp = cellstr(spm_select('FPList',[location,filesep,Order{csubj,1}], 'rp_af*.txt'));
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 = cellstr([location,filesep,Order{csubj,1}]); % this is folder to save to
my_file_name = 'headmotion'; % feel free to choose another extension
saving_name = strcat(my_saving_dir,filesep,my_file_name);
saveas(h,saving_name)
end|

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Oct. de 2013
If your rp is a cellstr() result, then it is a cell array. So rp(:,1:3) if it exists at all would be a cell array of strings. And you are trying to plot() that cell array.
Remember, cellstr() does not read data whose filenames are contained in the strings, and even if spm_select() is doing the reading, you cannot plot() a cell array.
  1 comentario
Victoria Klimaj
Victoria Klimaj el 14 de Oct. de 2013
Thanks! I tried rewriting the line as follows--no longer a cell array result, just trying to select the file. However, I having trouble with this too.
rp=spm_select('FPList',fullfile(location,filesep,Order{csubj,1}),'^rp*');
Originally, the script was able to plot an individual subject's file when it was not part of a for loop and the rp file was hand-chosen using the line "spm_select(spm_load)" instead of the line above. Any reason why that would work, but the line above does not?

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by