question about mesh or surf

6 Ansichten (letzte 30 Tage)
길수 정
길수 정 am 10 Mai 2023
Beantwortet: Gokul Nath S J am 22 Mai 2023
Hello cool guys. I'm suffering problem about plotting 3-dimension graph.
first, below is my code.
clear
N = 9;
M = 4;
theta = 0:pi/100:pi-pi/100;
phi = -pi/2:pi/100:pi/2-pi/100;
[T1 T2] = size(theta);
real_theta = pi/3;
real_phi = pi/3;
ay1 = [];
ay2 = [];
az1 = [];
az2 = [];
a1 = [];
a2 = [];
result1 = [];
result2 = [];
for L1 = 0:(N-1)
ay2 = [ay2 exp(1i*pi*L1*sin(real_theta).*sin(real_phi))];
end
for L2 = 0:(M-1)
az2 = [az2 exp(1i*pi*L2*cos(real_theta))];
end
for L3 = 1:N
a2 = [a2 (ay2(L3).*az2)];
end
for K1 = 0:(N-1)
ay1(K1+1,:) = exp(-1i*pi*K1*sin(theta).*sin(phi));
end
ay1 = ay1';
for K2 = 0:(M-1)
az1(K2+1,:) = exp(-1i*pi*K2*cos(theta));
end
az1 = az1';
for thn = 1:T2
for K3 = 1:N
a1 = [a1 (ay1(thn,K3).*az1(thn,:))];
end
result1(thn,:) = a1.*a2;
a1=[];
end
result1 = result1';
result2 = sum(result1);
[X, Y, Z] = meshgrid(cos(theta),sin(theta).*sin(phi),abs(result2));
surf(X,Y,Z)
Error using matlab.graphics.chart.primitive.Surface
Value must be a vector or 2D array of numeric type.

Error in surf (line 145)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
when I excute this code, error is displayed. the error is "value must be a vector or 2-dimension matrix"
How can i fix it? please let me know
  1 Kommentar
Adam Danz
Adam Danz am 10 Mai 2023
The doc page for surf describes each input variable. As the error message indicates, inputs must be vectors or 2D arrays. Your inputs are 3D arrays.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gokul Nath S J
Gokul Nath S J am 22 Mai 2023
Hi,
As per my understanding, it seems that you are receiving an error while using the surf plot. Note that you are creating a 3D grid and plotting the results. However, it is clear that your inputs itself is 3D matrixes. For getting a surf plot the visualization is taking place in the 3-dimension using a 2 variable equation since the function is mapping to the third dimension. If one goes along with the same argument here the function is mapping to the fourth dimension which is not capable of visualising. One workaround I can suggest is to try reducing the size of the matrix to 2D by inputing two arguments in the meshgrid and define your 2D domain. Further you can analyse the 3D function which might be a slice of fourth dimension you will be interested.
For further information please refer to the following documentation.
with regards,
Gokul Nath S J

Community Treasure Hunt

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

Start Hunting!

Translated by