Having problem plotting with surfc function

phi21 = linspace(-Tn,Tn,ns);
phi31 = linspace(-Tn,Tn,ns);
Tn=100;
ns=30;
P1=0;
alpha = 0;
beta = 0;
gama = 0;
[phi_21,phi_31] = meshgrid(phi21,phi31);
n=0;
for n=1:(2*n-1):21
P1(n)=(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180))
P1=P1+P1(n);
end
surfc(phi_21,phi_31,P1); colorbar;
I would like to surfc plot of equation P1 with respect to phi_21 and phi_31 upto 21st harmonic where n=1,3,5,7... this shows a dimension error like this "The surface Z must contain more than one row or column". Could anyone please help me with this?

2 comentarios

KSSV
KSSV el 14 de Mayo de 2018
P1 should me a matrix.
Mukul
Mukul el 14 de Mayo de 2018
How can I modify the code then?

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 15 de Mayo de 2018
You need to define Tn, ns, k12, and k13. Then get rid of the for loop.
% Guess at values.
Tn = .5;
ns = 100;
k12=4;
k13 = 3;
phi21 = linspace(-Tn,Tn,ns);
phi31 = linspace(-Tn,Tn,ns);
Tn=100;
ns=30;
P1=0;
alpha = 0;
beta = 0;
gama = 0;
[phi_21, phi_31] = meshgrid(phi21, phi31);
n = phi_21;
P1=(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+...
(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180));
surfc(phi_21,phi_31,P1, 'EdgeColor', 'none');
colorbar;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);

5 comentarios

Thanks for your effort. However, I couldn't understand why n=phi_21 ( this is angle and has defined earlier in the code). n is the harmonic number and should be 1.3.5.7....21. so I used the for loop in my code.
% n = phi_21;
Could you please advise on it?
Image Analyst
Image Analyst el 15 de Mayo de 2018
Perhaps you should explain in words more precisely what you want. How many surfaces do you want to generate?
I would like to generate one surface plot for the equation below P equation
P1(n)=(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180))
where the value of n should change such that n=1.3.5.7.9.11......21. So I will get P1(1), P1(3), P1(5), P1(7), P1(9).....P1(21) Now P=P1(1)+P1(3)+P1(5)+P1(7)+P1(9).....+P1(21) then I want to do surfc plot of P versus phi_12 and Phi_13
Image Analyst
Image Analyst el 15 de Mayo de 2018
Editada: Image Analyst el 15 de Mayo de 2018
What values do you have for k12 and k13?
Try this:
% Guess at values.
Tn=100;
ns=30;
k12=4;
k13 = 3;
phi21 = linspace(-Tn,Tn,ns);
phi31 = linspace(-Tn,Tn,ns);
Tn=100;
ns=30;
alpha = 0;
beta = 0;
gama = 0;
[phi_21, phi_31] = meshgrid(phi21, phi31);
P = zeros(size(phi_21));
for n = 1 : 21
thisP=(k12.*cos(alpha*pi*n/360).*cos(beta*pi*n/360).*sin(phi_21*pi*n/180))+...
(k13.*cos(alpha*pi*n/360).*cos(gama*pi*n/360).*sin(phi_31*pi*n/180));
P = P + thisP;
subplot(5, 5, n);
surfc(phi_21,phi_31, thisP, 'EdgeColor', 'none');
drawnow;
end
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Plot the sum of all the P's
figure;
surfc(phi_21,phi_31,P, 'EdgeColor', 'none');
colorbar;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
Mukul
Mukul el 16 de Mayo de 2018
Much appreciated your effort.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Mayo de 2018

Comentada:

el 16 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by