How to plot a 3d graph with z axis, not the same length as x,y

9 views (last 30 days)
I have a matrix of values where the first column is the x data (229 rows), then the next 52 columns (also 229 rows) are the corresponding y data at different times. I am trying to plot a 3d graph where the z direction is the y data at one of the times vs the x data. Does anyone know how to do this as mesh and surf require matrixes and stem3 requires all the vectors be the same length, where currently xdata (229x1), ydata(229x1) and zdata(52x1).

Answers (2)

Walter Roberson
Walter Roberson on 26 Jun 2019
Your ydata is not 229x1: it is 229x52.
You should repmat your z vector of length 52 to be 229x52.
  2 Comments
Fjdkrofoco
Fjdkrofoco on 26 Jun 2019
so I would use
rNew = repmat(r, [229, 52]);
but then ydata (229x52) and rNew (229x52) are matrixes but x stays a vector (229x1)? So the dimensions wouldn't match for mesh or surf?
Walter Roberson
Walter Roberson on 26 Jun 2019
y = YourMatrix(:,2:53);
x = repmat(YourMatrix(:,1), 1, size(y,2));
special_z_index = 7; %for example
z = repmat(y(special_z_index,:), size(y,1), 1);
surf(x, y, z, 'edgecolor', 'none')

Sign in to comment.


Star Strider
Star Strider on 26 Jun 2019
Interpolation is a favourite way to ‘stretch’ vectors.
If it conforms with your other requirements, try this:
zdataNew = interp1((1:52), zdata, linspace(1, 52, numel(xdata)));
figure
plot3(xdata, ydata, zdataNew)
grid on

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!