only saving last image
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 日
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);
Image Analyst
2022 年 9 月 2 日
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".
Image Analyst
2022 年 9 月 2 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
