How to plot data with >2 dimensions?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Rik
am 12 Okt. 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 Kommentare
Rik
am 12 Okt. 2020
Bearbeitet: Rik
am 12 Okt. 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
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!