How to plot data with >2 dimensions?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a variable of size 3x5x10000 and I want to plot this. The idea is that there are 5 trees which grow over 10000 timesteps in 3 different scenarios.
How could I get this in a plot which shows the growth of 5 trees over 10000 timesteps in 1 plot, and have 3 plots in total for each different scenario? The plot function can seemingly only use data with 2 dimensions.
0 comentarios
Respuestas (2)
Rik
el 12 de Oct. de 2020
Apart from plot3 (as Alan suggested), you may also consider using subplot to divide the different scenarios and using hold to plot the multiple trees in a single axes (or the reverse of course). The fact that your variable is 3D doesn't mean you need to actually plot your data in 3 dimensions.
2 comentarios
Rik
el 12 de Oct. de 2020
Editada: Rik
el 12 de Oct. de 2020
Use dh(1,1,:) instead, that will select the first element from each 3x5 block. If plot still complains, use squeeze to reduce the dimensionality of your array.
dh=rand(3,5,10000);
time=1:size(dh,3);
n=0;
for scenario=1:size(dh,1)
ax=subplot(1,3,scenario);
cla(ax);%only for debugging: clear axes contents
hold(ax,'on');
for tree=1:size(dh,2)
name=sprintf('tree %d',tree);
plot(time,squeeze(dh(scenario,tree,:)),'DisplayName',name,'Parent',ax);
end
hold(ax,'off');
title(sprintf('scenario %d',scenario))
legend(ax)
end
Ver también
Categorías
Más información sobre Axis Labels 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!