only saving last image
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
hi, this is my code. Figures are plotted correctly but only the last " i " image was saved for all iterations. Please advise which part was wrong. thanks.
for m = 1: size (OSI,1)
if OSI (m) > 0.5
for i = 1: size (trial_trace,3)
p(i) = figure (i);
for j = 1:5
subplot(5,1,j)
for k = 1:8
if j ~= 5
plot (trial_stimstarts_reset(j,k):trial_stimends_mod_reset(j,k), trial_trace{j,k,i})
ylabel(sprintf('Trial %d', j))
if j == 1
title (sprintf('ROI %d: OSI %0.2f DSI %0.2f', m, OSI(m), DSI (m)))
end
elseif j == 5
plot (trial_stimstarts_reset(1,k):trial_stimends_mod_reset(1,k), trial_trace_avg{1,k,i})
ylabel('Average')
end
hold on
end
end
end
cd(path_stim_all{itr})
saveas (p(i),strcat('trace_','ROI', '_', num2str(m), '_', 'OSI', '_', num2str (OSI(m)), 'DSI', '_', num2str (DSI(m)), '.jpeg'));
end
end
채택된 답변
Image Analyst
2022년 9월 2일
0 개 추천
saveas() needs to be inside the loop over i. Right now it's between the end of the i loop but before the end of the m loop.
댓글 수: 10
HYZ
2022년 9월 2일
I put saveas between the last 'end' and second last 'end'. It still doesn't solve the issue.
Image Analyst
2022년 9월 2일
편집: Image Analyst
2022년 9월 2일
Set a breakpoint there. Does the value of p(i) change? Maybe just get rid of that in saveas so that it saves the current figure. Have it print out the filename first.
fileName = sprintf('trace_ROI_%2.2d_OSI_%2.2d DSI_%2.2d.jpg', m, OSI(m), DSI(m));
fprintf('For i=%d and m=%d, Saving "%s".\n', i, m, fileName);
exportgraphics(gcf, fileName);
HYZ
2022년 9월 2일
I ran your code. I got back the below error.
for m = 1: size (OSI,1)
if OSI (m) > 0.5
for i = 1: size (trial_trace,3)
p(i) = figure;
for j = 1:5 % 4trials + average trial
subplot(5,1,j)
for k = 1:8 % direction
if j ~= 5
plot (trial_stimstarts_reset(j,k):trial_stimends_mod_reset(j,k), trial_trace{j,k,i},'-k')
a = trial_stimstarts_reset(1,k) ;
c = min(cell2mat(trial_trace(j,:,i))); d = max(cell2mat(trial_trace(j,:,i)));
patch([a a+10 a+10 a], [c c d d],[.75 .75 .75],'FaceAlpha',0.3, 'Edgecolor', 'none')
ylabel(sprintf('Trial %d', j))
hold on
elseif j == 5
plot (trial_stimstarts_reset(1,k):trial_stimends_mod_reset(1,k), trial_trace_avg{1,k,i},'-k')
a = trial_stimstarts_reset(1,k) ;
c = min(cell2mat(trial_trace_avg(:,:,i))); d = max(cell2mat(trial_trace_avg(:,:,i)));
patch([a a+10 a+10 a], [c c d d],[.75 .75 .75],'FaceAlpha',0.3, 'Edgecolor', 'none')
ylabel('Average')
xlabel('#frames')
hold on
end
hold on
end
end
cd(path_stim_all{itr})
fileName = sprintf('trace_ROI_%2.2d_OSI_%2.2d DSI_%2.2d.jpg', m, OSI(m), DSI(m));
fprintf('For i=%d and m=%d, Saving "%s".\n', i, m, fileName);
exportgraphics(gcf, fileName);
end
end
end
For i=1 and m=1, Saving "trace_ROI_01_OSI_5.25e-01 DSI_5.84e-01.jpg".
For i=2 and m=1, Saving "trace_ROI_01_OSI_5.25e-01 DSI_5.84e-01.jpg".
For i=3 and m=1, Saving "trace_ROI_01_OSI_5.25e-01 DSI_5.84e-01.jpg".
Error using exportgraphics
The value of 'destination' is invalid. Unable to create output file 'trace_ROI_01_OSI_5.25e-01 DSI_5.84e-01.jpg', Permission
denied.
Error in sandbox04 (line 156)
exportgraphics(gcf, fileName);
Notice that all your filenames are the same. Are OSI and DSI floating point numbers or integers? If they are floating point, change it to
fileName = sprintf('trace_ROI_%2.2d_OSI_%.2f DSI_%.2f.jpg', m, OSI(m), DSI(m));
Is the filename supposed to have 'i' encoded into it? Right now the filename does not change with the value of i.
yes. The filename is not supposed to have i and only encoded into m.
It saved all images for i = 8. basically, it saved only the last i for different m. I put the code before the last two ends.
If I don't save images, the displayed matlab images showed the correct figures. only when I tried to save, same images were saved.
end
cd(path_stim_all{itr})
fileName = sprintf('trace_ROI_%0.2f_OSI_%0.2f DSI_%0.2f.jpg', m, OSI(m), DSI(m));
fprintf('For i=%d and m=%d, Saving "%s".\n', i, m, fileName);
exportgraphics(gcf, fileName);
end
end
For i=8 and m=1, Saving "trace_ROI_1.00_OSI_0.52 DSI_0.58.jpg".
For i=8 and m=2, Saving "trace_ROI_2.00_OSI_0.75 DSI_0.16.jpg".
For i=8 and m=3, Saving "trace_ROI_3.00_OSI_0.62 DSI_0.21.jpg".
For i=8 and m=15, Saving "trace_ROI_15.00_OSI_0.56 DSI_0.00.jpg".
For i=8 and m=21, Saving "trace_ROI_21.00_OSI_0.72 DSI_0.02.jpg".
For i=8 and m=29, Saving "trace_ROI_29.00_OSI_0.55 DSI_0.14.jpg".
For i=8 and m=56, Saving "trace_ROI_56.00_OSI_0.51 DSI_0.20.jpg".
For i=8 and m=98, Saving "trace_ROI_98.00_OSI_0.58 DSI_0.17.jpg".
Can you save yoiur variables into a mat file so I can run your program, like
save('yuzhi.mat', 'trial_stimstarts_reset', 'trial_trace', ...
'trial_stimends_mod_reset', 'trial_trace_avg',...
'OSI', 'DSI', 'trial_trace');
and any others that I may have forgotten? Then attach yuzhi.mat with the paperclip icon.
HYZ
2022년 9월 2일
I attached the variables "yuzhi.mat". thanks in advance!
Image Analyst
2022년 9월 2일
Please add path_stim_all to the list. It's bombing when it gets to that line.
HYZ
2022년 9월 2일
I reattached the .mat.
path_stim_all{itr} is just for where to save. sorry forgot to mention.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
