How to plot and save the content of a 5D array?
12 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a 5 dimension array M_ii (attached). It's size is 25x50x3x14x2. I want to plot and save the following on the same figure
M_ii(bb,:,1,1,1)
M_ii(bb,:,2,1,1)
M_ii(bb,:,3,1,1)
And do the same thing for the rest M_ii(:,:,:,pp,ii).
for ii = 1:length(tol)
for pp = 1:length(p)
for bb = 1:length(bgt)
for kk = 1:length(trigger)
plot(1:length(M_ii(bb,:,kk,pp,ii)),M_ii(bb,:,kk,pp,ii))
end
savefig(sprintf('traj.mat'),..)
end
end
end
I want to save all the resulting figures as .fig files but without displaying them when I run the code above. For the names of the figures, I want something like this: traj151. Where the first one represents bb=1 and number 5 represents pp=5 and the seconed one represents ii=1
Your help and ideas would be appreciated.
0 件のコメント
採用された回答
Steven Lord
2022 年 8 月 4 日
Is your main question how to assemble the file name? I'd use a string array.
n = 1;
p = 42;
q = 999;
filename = "part" + n + "of" + p + "ForUserID" + q + ".txt"
Or if you need specific formatting, then I'd use sprintf. Note the extra 0 in the display of n in filename2.
filename2 = sprintf("part%02dof%dForUserID%d.txt", n, p, q)
3 件のコメント
Steven Lord
2022 年 8 月 4 日
If you expected this code:
filename = sprintf("bgt%02dp%02dForaID%d.txt", bb, pp, ii);
savefig('filename.fig')
to write to a file whose name is stored in the variable filename, that is not what it does. This code writes to a file whose name is literally filename.fig. If you want to use the contents of the variable as the file name, you need to pass the variable into savefig as an input.
filename = "file1773965.fig";
savefig(filename) % Creates a file named file1773965.fig
savefig('filename') % Creates a file named filename
That savefig(filename) call is equivalent to:
savefig("file1773965.fig")
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!