How to plot data with >2 dimensions?
18 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Rik
on 12 Oct 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 Comments
Rik
on 12 Oct 2020
Edited: Rik
on 12 Oct 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
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!