saving a figure within a loop
조회 수: 2 (최근 30일)
이전 댓글 표시
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|
댓글 수: 0
답변 (1개)
Walter Roberson
2013년 10월 13일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!