Plotting multiple 2D line plots from a 3D matrix
조회 수: 11 (최근 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!