surf plot 3d - matrix multiplication

조회 수: 2 (최근 30일)
Housam
Housam 2020년 2월 28일
답변: Housam 2020년 3월 2일
Hello,
could someone let me know how to get around this problem in the code.
i need to do the following: 1- plot the surf 2- multiply with RS matrix 3- make a new surf
angle1_min=0; angle1_max=pi/2; %all 8 Octant in 3d [0-2*pi]
angle2_min=0; angle2_max=pi/2;
number1=50; number2=2500; number3=51; %xlsread
[angle1, angle2] = ndgrid(linspace(angle1_min,angle1_max,100),linspace(angle2_min,angle2_max,100)) % size 100*100 (for using surf)
x= number1*sin(angle1)*sin(angle2)
y= number2*cos(angle1)
z= number3*sin(angle1)*cos(angle2)
surf(x, y, z) % works fine
mat = [x; y; z] % size mat here 300*100 (depend on angle size)
RS = [1 0 0; 0 1 0; 0 0 1] % size 3*3
new_mat = RS * mat % Matrix Multiplication is required- RS is to be kept
surf(new_mat)
i tried to use a function with for loop that return one point for mat with the size 1*3 then i multiplied it with RS matrix. at the end i plotted all the points using surf but its not what i expected.

채택된 답변

Housam
Housam 2020년 3월 2일
rotate

추가 답변 (1개)

darova
darova 2020년 2월 28일
You forgot about dot here (bit-wise operator)
x= number1*sin(angle1).*sin(angle2);
y= number2*cos(angle1);
z= number3*sin(angle1).*cos(angle2);
You want to rotate data
mat = [x(:); y(:); z(:)]'; % size mat here 1e4x3
RS = [1 0 0; 0 1 0; 0 0 1] % size 3*3
new_mat = RS * mat % Matrix Multiplication is required- RS is to be kept
x1 = reshape( new_mat(1,:),size(x) );
y1 = reshape( new_mat(2,:),size(y) );
z1 = reshape( new_mat(3,:),size(z) );
surf(x1,y1,z1)
  댓글 수: 1
Housam
Housam 2020년 3월 2일
thanks, i used a matlab function called rotate.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by