surf plot 3d - matrix multiplication

2 次查看(过去 30 天)
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)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by