필터 지우기
필터 지우기

Change size 3D matrix

조회 수: 2 (최근 30일)
Francesco Guaresi
Francesco Guaresi 2019년 11월 2일
댓글: the cyclist 2019년 11월 2일
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
the cyclist
the cyclist 2019년 11월 2일
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
Francesco Guaresi 2019년 11월 2일
편집: Francesco Guaresi 2019년 11월 2일
The entire code works, except this plot. The error message is:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in Isothermal_PFR_EP3_tensor_plot_3D (line 437)
surf(vector_1,vector_2,EP(f,:,:),'Color',col(f,:,:));

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2019년 11월 2일
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
Francesco Guaresi
Francesco Guaresi 2019년 11월 2일
Thank you very much! Imposing view(15,15) it works perfectly!
But is it possible to obtain the 4 surfaces in 4 different colors?
the cyclist
the cyclist 2019년 11월 2일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by