Change size 3D matrix
Show older comments
Hi, I have a 3D matrix defined as: EP(N,k,r) and I want to plot its values as different surfaces at constant N. So I tried to plot this matrix in this way:
col=hsv(N);
figure
hold on
for f=1:N
surf(vector_1,vector_2,EP(f,:,:),'Color',col(f,:,:));
legendInfo{f} = [num2str(Temp(f)-273.15) ' °C'];
end
legend(legendInfo)
but it doesn't work. It seems I can only plot surfaces at constant r! So now I want to try to plot a new matrix in the form (k,r,N).
How can I change the dimension of matrix EP(N,k,r) (and so its values inside) in this form: EP_1(k,r,N)?
6 Comments
darova
on 2 Nov 2019
You want to plot slices of a volume?
Francesco Guaresi
on 2 Nov 2019
darova
on 2 Nov 2019
What about slice or volumeslice?
Francesco Guaresi
on 2 Nov 2019
Edited: Francesco Guaresi
on 2 Nov 2019
the cyclist
on 2 Nov 2019
When you say, "it doesn't work", what do you mean, specifically? Do you mean that the code runs, but gives an unexpected result, or that the code does not run, and gives an error? If that latter, please post the complete error message.
Francesco Guaresi
on 2 Nov 2019
Edited: Francesco Guaresi
on 2 Nov 2019
Answers (1)
the cyclist
on 2 Nov 2019
I think what you want is to use
permute(EP(f,:,:),[2 3 1])
as the input, instead of just EP(f,:,:), so that you have a 2-d matrix, rather than a 3-d (in which the first dimension has length 1).
6 Comments
Francesco Guaresi
on 2 Nov 2019
the cyclist
on 2 Nov 2019
Can you upload the variables that you are using to make the plot, in a *.mat file?
Francesco Guaresi
on 2 Nov 2019
the cyclist
on 2 Nov 2019
MATLAB seems to have chosen a poor default view, which fails to illustrate the 3-D nature of the plot. Try adding
view(45,45)
after the plot, and you'll see something closer to what you expect.
Francesco Guaresi
on 2 Nov 2019
the cyclist
on 2 Nov 2019
The surf command takes a fourth argument, for the color. You could write your loop in a way that uses a different color for each loop iteration.
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
