How to detached 3D plot from excel data

I'm new to MATLAB and have a matrix with a set of x-values and 24 different sets of y values. I normally represent them as 24 2D plots overlayed but I'd like to plot a 3D graph with this data. How do I include the y values and plot a 3D scatter or surface plot?
The data is in a matrix like below where M(1) is not defined:
M=[NaN 1 2 ... 24
1 5 3 ... 3
2 3 1 ... 3
3 2 2 ... 5
4 1 1 ... 3
5 4 2 ... 5]
The first column contains the x values and the next 24 columns contain the z value (for the dataset that I'm using, each is a different temperature value) followed by the y values. Currently, I do:
hold on
for n=2:24
plot(M(2:size(M,1)), M(2:size(M,1), n))
end
hold off
This gives me 24 2D plots on the same graph. However, I'd like to plot this on a 3D graph such that each x-y plot is at a different z value.

2 Comments

If you have no problem to import your data from your Excel file, why is it important to talk about Excell file. Can you explain the meaning of: 24 different series of y values, each corresponding to a different z-value ? to make your question clear, post a short example and explain what you want: for example
M=[0 4 4 3
1 5 3 3
2 3 1 3
3 2 2 5
4 1 1 3
5 4 2 5]
So column 1 is x, followed by z in column 2, and followed by 22 y values in columns 3-24 - right (because that's what you said when you said "the next 24 columns contain the z value...followed by the y values")?
Why is there a nan for the first element of x?
I'd extract out x and z and y
x = M(:,1);
z = M(:, 2);
y = M(:, 3:end);
Also, you didn't say anything about the answers you got so far, like about waterfall and ribbons. What do you think of those? Do you have some kind of plot that you'd like to see?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 23 Jul 2016
Edited: Image Analyst on 23 Jul 2016
Not clear what you want. All I can guess so far is that the waterfall() function may be what you're looking for.
The y would be the vertical direction and the x the continuous direction, then each curve is plotted along a new z value in the discrete z direction. In other words, in the plot above, each curve is in a x-y plane and there are 30 z values with one curve for each z value.
Star Strider
Star Strider on 23 Jul 2016
Edited: Star Strider on 23 Jul 2016
I would go with a ribbon plot. It would depict your data most clearly.
EDIT A ribbon plot of simulated (Nx24) matrix data (here, N=100):
t = linspace(0,1); % Create Data
M = [[1:length(t)]' sin(2*pi*[1:0.125:3.75]'*t)']; % Create Data
figure(1)
ribbon(M(:,1), M(:,2:end))
grid on
xlabel('Column #')
ylabel('Row #')
axis([0 24 ylim zlim])
title('Ribbon Plot')

4 Comments

Some of his z are repeated. Look at column 2 - the z values. There are two elements that have a z value of 1, meaning that two ribbons would be in the "same slice". There may be even more duplicates in a larger array. When plotted, the ribbons may even need to cross. Can the ribbon command do that?
We need the data file in order to determine the best approach.
From my reading of the Question, ribbon will work.
I'm beginning to think he worded it totally wrong, or at least confusingly. He said the "first column contains the x values and the next 24 columns contain the z value, followed by the y values." To me, that means that in the first column are the x values, then the next column is the z values, then followed by columns of the y values.
I think he may really mean the columns are x (in column 1) and followed by columns of the y values (in columns 2 - 24) - and x is not followed by the z values. I'm thinking the z values may actually be in row #1, rather than in column #2 following the x column.
I just read it and made my best guess as to what the file was and what was wanted. The plot loop in the original post just obfuscates the issue.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 23 Jul 2016

Commented:

on 24 Jul 2016

Community Treasure Hunt

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

Start Hunting!