How to plot and save the content of a 5D array?

10 visualizaciones (últimos 30 días)
Waseem AL Aqqad
Waseem AL Aqqad el 4 de Ag. de 2022
Comentada: Waseem AL Aqqad el 6 de Ag. de 2022
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.

Respuesta aceptada

Steven Lord
Steven Lord el 4 de Ag. de 2022
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"
filename = "part1of42ForUserID999.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)
filename2 = "part01of42ForUserID999.txt"
  3 comentarios
Steven Lord
Steven Lord el 4 de Ag. de 2022
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")
Waseem AL Aqqad
Waseem AL Aqqad el 6 de Ag. de 2022
Thank you so much, Steven.
I'm sorry for my late reply.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by