How to visualize or (plot) a 3D matrix in convenient way?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jacky Jo
el 21 de Sept. de 2015
Respondida: Walter Roberson
el 22 de Sept. de 2015
The matrix P_bar is 3 dimensional. It has upper diagonal elements all zeros. In other words, if we consider it as a rectangular shaped prism, upper half has been removed or has null values, and using recursion lower part has been created.
I just want to see my matrix (P_bar) in 3D (If possible, all values inside that matrix in that plot with different colours).
Please help me,... Thanks in advance.
The code is given below:
d
% Legendre Polynomials
clc; clear all; close all;
L_max=input('Enter the Degree (L_max) =');
M=input('Enter the Oder (M) =');
if M>L_max
fprintf('\n\n\n\t\tError!\n\nPlease enter Degree>Order!\n');
quit cancel;
else
if M==0
Delta_M=1;
else
Delta_M=0;
end
theta=[0:1:180]'; % Co-latitude matix with 1 degree interval
Cos_theta(1,1,1:181)=cosd(theta);
Sin_theta(1,1,1:181)=sind(theta);
Cot_theta(1,1,1:181)=cotd(theta);
P_bar(1,1,1:181)=1/4*pi; % P_bar(0,0)----> Eqution(4)
for m=1:M
% P_bar(m,m)----> Eqution(5)
P_bar(m+1,m+1,1:181)= Sin_theta *sqrt( ((2*(m-1)+3)*(1+ Delta_M))/ (2*(m-1)+2) ).*P_bar(m,m,1:181);
% P_bar(m+1,m)----> Eqution(6)
P_bar(m+1,m,1:181) = Cot_theta *sqrt( (2*(m-1)+2) / (1+ Delta_M) ).*P_bar(m+1,m+1,1:181);
% P_bar(l+1,m)----> Eqution(7)
for l=(m+1):L_max
P_bar(l+1,m,1:181) = Cos_theta *sqrt((2*(l-1)+3) * (2*(l-1)+1)/ ((l-1)-(m-1)+1) * ((l-1)+(m-1)+1)) .*P_bar(l,m,1:181)-( sqrt((2*(l-1)+3) * ((l-1)*(l-1)-(m-1)*(m-1))/ (2*(l-1)-1) * (((l-1)+1) * ((l-1)+1) -(m-1)*(m-1))) *P_bar(l-1,m,1:181) );
end
end
figure; plot(theta,P_bar(:,1:181),'linewidth',1.4);
end
0 comentarios
Respuesta aceptada
Walter Roberson
el 22 de Sept. de 2015
[X,Y,Z] = ndgrid(1:181,1:L_max+1,1:M+1);
PP = permute(P_bar,[3 1 2]);
h = plot3(reshape(X,181,[]), reshape(Y,181,[]), reshape(PP,181,[]));
%now recolor them
cmap = hsv(length(h));
for K = 1 : length(h)
set(h(K),'Color',cmap(K,:))
end
[Lidx,Midx] = ndgrid(1:L_max+1,1:M+1);
legends = cellstr(num2str([Lidx(:),Midx(:)],'L = %d, M = %d'));
legend(legends);
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!