Plotting multiple 2D line plots from a 3D matrix
26 次查看(过去 30 天)
显示 更早的评论
I have a 3D matrix, for simplicity let's say its 10x10x100. I want to create mutiple line plots (on the same figure), which use the Z-dimension of the matrix as the size of X-axis for the line plot, and then the plot Y value at each Z point will be the amplitude at the location X, Y, Z and we will have 100 line plots in total. So for example, if we choose X = 3, Y = 4, then I want to return a line plot of this location through the 100 cells of dimesion Z.
The aim here is to create line plots for each X, Y position (a 1x100 line) such that we have 10 x 10 lines each of length Z, and a plot which is then composed of the 100 line plots.
So far I have only been able to extract a single 1x1x100 matrix and use 'squeeze' to create a 2D line plot, however I want to be able to create many lines at once if this is possible,
Thank you!
0 个评论
采纳的回答
Abdolkarim Mohammadi
2020-8-25
编辑:Abdolkarim Mohammadi
2020-8-25
In order to use plot() efficiently, you should prepare the data to call it just one time. plot() treats each column of 2D arrays as a separate line. So if you had, for example, a 3x4x5 matrix, you need 12 lines of 5 points. You should first permute the matrix and then reshape it to have all of the data in columns. If M is your dataset, then:
M = rand (3, 4, 5);
Dim = size (M);
M2 = permute (M, [3,2,1]);
M3 = reshape (M2(:), Dim(3), []);
plot (M3);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!