MATLAB: Contour plot: how to plot matrix Z as the y-axis and array Y as the levels

contourcontourf

I have generated a matrix Z of data, by looping arrays X and Y in nested for-loops in order to generate solutions for all possible combinations of X and Y. Z is thus indirectly a function of X and Y, but I can't write it as an equation as Z is calculated numerically.
In one particular case I have X being a 1×35065 array, Y a 1×121 array and Z a 35065×121 matrix.
I plotted the contour using
contourf(X, Y, Z')
I now want to generate a second contour plot, by having the Z matrix on the y-axis and the levels denoted by the Y array. I can't figure out how to generate the new Y2 matrix and the Z2 array to plot this (X stays the same). Basically I am looking for the routine to generate Y2 and Z2 from my existing Y and Z data in order to be able to call
contourf(X, Z2, Y2)

Best Answer

  • I have generated a matrix Z of data, by looping arrays X and Y in nested for-loops
Use meshgrid to create X and Y as matrices
[X1,Y1] = meshgrid(X,Y);
Related Question