Tn = 100;
ns = 30;
alpha = 0
beta = 0
gama = 0
phi1 = linspace(-Tn,Tn,ns);
phi2 = linspace(-Tn,Tn,ns);
phi3 = linspace(-Tn,Tn,ns);
%Phase Angle Mesh-Grid
[phi_1,phi_2,phi_3] = meshgrid(phi1,phi2,phi3);
phi_12 = phi_2 - phi_1;
phi_21 = phi_1 - phi_2;
phi_13 = phi_3 - phi_1;
phi_31 = phi_1 - phi_3;
phi_23 = phi_3 - phi_2;
phi_32 = phi_2 - phi_3;
k11 = 917.3770;
k22 = 917.3770;
k33 = 917.3770;
k12 = 458.6885;
k13 = 458.6885;
k23 = 458.6885;
X = -(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_12*pi*n/180))-(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_13*pi*n/180))
Y = -(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+(k23.*cos(beta*pi*n/360).*cos(gama*pi*n/360).*sin(phi_23*pi*n/180))
Z = -(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180))+(k23.*cos(beta*pi*n/360).*cos(gama*pi*n/360).*sin(phi_32*pi*n/180))
figure(1);
surfc(phi_12,phi_13,X); colorbar;
figure(2);
surfc(phi_21,phi_23,Y); colorbar;
figure(3);
surfc(phi_31,phi_32,Z); colorbar;
Getting the following error:
Error using matlab.graphics.chart.primitive.Surface/set
Value must be a vector or 2D array of numeric type
Error in matlab.graphics.chart.internal.ctorHelper (line 8)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 150)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
Error in surfc (line 53)
hs = surf(cax, args{:});
Error in (line 68)
surfc(phi_12,phi_13,X); colorbar;
can anyone please help me fixing this error?

6 Kommentare

Star Strider
Star Strider am 20 Mai 2018
If you request 2 outputs from meshgrid, the matrices are 2D, and 3 outputs, 3D. So here, they are all (30x30x30). The surf function only works with 2D matrices (and optionally, vectors for the first two arguments).
That is the problem. You have to solve it.
Mukul
Mukul am 20 Mai 2018
I know this error is related to the matrix dimension. How can I resolve it? Any help much appreciated?
Image Analyst
Image Analyst am 20 Mai 2018
I have no idea what all those trillions of phi's are. Make it easy for us to understand your code by putting in some comments to explain what each line of code does.
Tn = 100;
ns = 30;
alpha = 0
beta = 0
gama = 0
phi1 = linspace(-Tn,Tn,ns); % this is an angle -100 to 100 degree
phi2 = linspace(-Tn,Tn,ns); % this is an angle -100 to 100 degree
phi3 = linspace(-Tn,Tn,ns);% this is an angle -100 to 100 degree
%Phase Angle Mesh-Grid
[phi_1,phi_2,phi_3] = meshgrid(phi1,phi2,phi3);
phi_12 = phi_2 - phi_1; % phi_12 is the angle difference between phi_2 and phi_1 which is the actual angle of sin in the X equation and phi_21 is the negative of phi_12 in Y equation. this is same for phi_13 and phi_23
phi_21 = - phi_12;
phi_13 = phi_3 - phi_1;
phi_31 = - phi_13;
phi_23 = phi_3 - phi_2;
phi_32 = - phi_23;
k11 = 917.3770; % just constant
k22 = 917.3770;
k33 = 917.3770;
k12 = 458.6885;
k13 = 458.6885;
k23 = 458.6885;
X = -(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_12*pi*n/180))-(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_13*pi*n/180))
Y = -(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+(k23.*cos(beta*pi*n/360).*cos(gama*pi*n/360).*sin(phi_23*pi*n/180))
Z = -(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180))+(k23.*cos(beta*pi*n/360).*cos(gama*pi*n/360).*sin(phi_32*pi*n/180))
figure(1);
surfc(phi_12,phi_13,X); colorbar;
figure(2);
surfc(phi_21,phi_23,Y); colorbar;
figure(3);
surfc(phi_31,phi_32,Z); colorbar;code
please ask for further clarifications if need.
Star Strider
Star Strider am 20 Mai 2018
Describe what you want to do.
Mukul
Mukul am 21 Mai 2018
Bearbeitet: Stephen23 am 21 Mai 2018
Just think in a very simple way: since alpha, beta and gama is zero, so the cos term is 1 and then the X Y and Z equation becomes
X=-k*sin(phi_12)-k*sin(phi_13)
Y=-k*sin(phi_21)+k*sin(phi_23)
Z=-k*sin(phi_31)+k*sin(phi_32)
Where
k=917.377
phi_12 = phi_2 - phi_1;
phi_21 = - phi_12;
phi_13 = phi_3 - phi_1;
phi_31 = - phi_13;
phi_23 = phi_3 - phi_2;
phi_32 = - phi_23;
Now I would like to do surfc plot of X in terms of phi_12, phi_13, Y in terms of phi_21 and phi_23 and Z in terms of phi_31 and phi_32 over the range of phi_1, phi_2 and phi_3 is -100 degree to 100 degree.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Mai 2018

1 Stimme

You need to use isosurface() instead of surfc()

10 Kommentare

Using isosurface gives me the following error:
Error using isosurface (line 68)
Isovalue must be a scalar.
Walter Roberson
Walter Roberson am 21 Mai 2018
Call isosurface() once for each value you wish to use as an isolevel.
Mukul
Mukul am 22 Mai 2018
Bearbeitet: Mukul am 22 Mai 2018
Thanks Walter for your comment.
Could you please tell me where I need to modify the code for calling isosurface. Still I am getting issues with running the code. I have written the following code:
k=917.377
Tn = 100;
ns = 30;
phi1 = linspace(-Tn,Tn,ns);
phi2 = linspace(-Tn,Tn,ns);
phi3 = linspace(-Tn,Tn,ns);
[phi_1,phi_2,phi_3] = meshgrid(phi1,phi2,phi3);
phi_12 = phi_2 - phi_1;
phi_21 = - phi_12;
phi_13 = phi_3 - phi_1;
phi_31 = - phi_13;
phi_23 = phi_3 - phi_2;
phi_32 = - phi_23;
X=-k*sin(phi_12)-k*sin(phi_13)
Y=-k*sin(phi_21)+k*sin(phi_23)
Z=-k*sin(phi_31)+k*sin(phi_32)
figure(1);
isosurface(phi_12,phi_1,X); colorbar;
Basically I need to do surface plot of X in terms of phi_12, phi_13, Y in terms of phi_21 and phi_23 and Z in terms of phi_31 and phi_32 over the range of phi_1, phi_2 and phi_3 are -100 degree to 100 degree.
Your phi_1, phi_2, phi_3 are 3D, plus you have one result value for each location, for a total of 4 dimensions of information. You can plot that in 3 dimensions using isosurface(), but only if you give 3 dimensions of input coordinates along with the resulting variable. For example,
isosurface(phi_1,phi_2,phi_3,X,0)
You, though, are trying to use two input coordinates for the graph, with each of the two input coordinates derived from 3D coordinates, so you have coordinates that a really 3D but you only have 2 of them.
Perhaps you want something like
scatter(phi_12(:), phi_13(:), 20, X(:));
To convert that to a contour plot you would need to use one of the scattered interpolants, perhaps griddata()
Mukul
Mukul am 5 Jun. 2018
Thank you for your comment Walter. The scatter plot works but what is my concern is that:
The resulting variable X, Y and Z would be all symmetric after plotting and should look like similar.
But with the contour plot and surfc plot, I am getting the variables Y and Z similar but X is not same as Y and Z.
Could you please comment on it and help me to find out the reason why this is happening?
To confirm we are talking about the same thing:
k=917.377;
Tn = 100;
ns = 30;
phi1 = linspace(-Tn,Tn,ns);
phi2 = linspace(-Tn,Tn,ns);
phi3 = linspace(-Tn,Tn,ns);
[phi_1,phi_2,phi_3] = meshgrid(phi1,phi2,phi3);
phi_12 = phi_2 - phi_1;
phi_21 = - phi_12;
phi_13 = phi_3 - phi_1;
phi_31 = - phi_13;
phi_23 = phi_3 - phi_2;
phi_32 = - phi_23;
X=-k*sin(phi_12)-k*sin(phi_13);
Y=-k*sin(phi_21)+k*sin(phi_23) ;
Z=-k*sin(phi_31)+k*sin(phi_32) ;
figure(1);
subplot(1,3,1)
scatter(phi_12(:), phi_13(:), 20, X(:));
axis equal
subplot(1,3,2)
scatter(phi_12(:), phi_13(:), 20, Y(:));
axis equal
subplot(1,3,3)
scatter(phi_12(:), phi_13(:), 20, Z(:));
axis equal
Is the difficulty that the graph for X appears to have circular regions, but the graphs for Y and Z have ovals instead of circles?
Mukul
Mukul am 7 Jun. 2018
Bearbeitet: Mukul am 7 Jun. 2018
Yes the problem is exactly that. I am expecting all the X, Y and Z to be similar in characteristics that means symmetric.
if I assume phi1 to be zero, then the equations should be like this:
X = (k12.*sin(phi_21))+ (k13.*sin(phi_31))
Y = -(k12.*sin(phi_21))+(k23.*sin(phi_23))
Z = -(k13.*sin(phi_31))+(k23.*sin(phi_32))
and if I plot like this
Tn = pi/2;
ns = 30;
K12 =k13=k23=458;
phi21 = linspace(-Tn,Tn,ns);
phi31 = linspace(-Tn,Tn,ns);
figure(1);
surfc(phi_21,phi_31,X); colorbar;
figure(2);
surfc(phi_21,phi_23,Y); colorbar;
figure(3);
surfc(phi_31,phi_32,Z); colorbar;
I am getting the figures X, Y and Z which are attached fot you to look at. You can see that Y and Z are similar but X is not. I want all three figures to be similar.
Mukul
Mukul am 20 Jun. 2018
Can anyone tell me what should be the problem looking at the three figures X, Y and Z and code?
The shape of these three figures must be same.
Walter Roberson
Walter Roberson am 20 Jun. 2018
I don't think they should be the same. You are defining coordinates parametrically in different ways, and I see no reason why the shapes should all have the same angle when converted to one fixed set of coordinates.
I think that it is more likely that you can choose different coordinate basis that would make a different pair of the two look the same, and a third coordinate basis that make the remaining pair look the same -- each time there being one that looked different.
Using phi_12(:), phi_13(:) as a consistent arbitrary projection affects how the shapes look. Why should that pair of coordinates for the projection be any more right than, say, phi_23(:), phi_13(:) ?
Mukul
Mukul am 22 Jun. 2018
Bearbeitet: Walter Roberson am 22 Jun. 2018
Hi Walter thank you for your comments:
If I try in other ways without using the mesh grid function, I am getting these shapes where the three shapes looks almost same
Tn = pi/2;
ns = 30;
for i=1:40
for j=1:40
phi12 = pi/4*((i-20)/20);
phi23 = pi/4*((j-20)/20);
phi31 = -phi23 - phi12;
X(i,j)=sin(phi12)-sin(phi31);
Y(i,j)=-sin(phi12)+sin(phi23);
Z(i,j)=-sin(phi23)+sin(phi31);
end
end
a=1:40;
b=a;
aon2=10:30;
bon2=aon2;
figure(1);
surfc(a,b,X); colorbar;
figure(2);
surfc(a,-b,Y); colorbar;
figure(3);
surfc(-a,-b,Z); colorbar;
end
Do you think in the previous case, the mesh grid function causes the shapes not to be same?
Could you please comment on this?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by