How to visualize or (plot) a 3D matrix in convenient way?

4 ビュー (過去 30 日間)
Jacky Jo
Jacky Jo 2015 年 9 月 21 日
回答済み: Walter Roberson 2015 年 9 月 22 日
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

採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 22 日
[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 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by