Plotting multiple 2D line plots from a 3D matrix
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Eunan McShane
il 25 Ago 2020
Modificato: Abdolkarim Mohammadi
il 25 Ago 2020
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 Commenti
Risposta accettata
Abdolkarim Mohammadi
il 25 Ago 2020
Modificato: Abdolkarim Mohammadi
il 25 Ago 2020
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!