Creating 3D plot from a n*n matrix

I wanted to create a 3D plot from a 100*100 matrix, with two other vectors with length 100 that serves as the axis for the plot.
This was the code that I wrote but the most of it is just defining the main matrix, the important part is at the bottom where its supposed to make the 3D plot.
N = 100;
ka = linspace(0,0.99,100);
pa = linspace(0,pi/2,100);
K = zeros(N,1);
E = zeros(N,1);
for i = 1:N
for n = 1:N
k = ka(i);
p = pa(n);
funK=@(t)(1-(k^2)*(sin(t)).^2).^(-0.5);
Kf=@(x)integral(funK,0,x);
K(i,n) = Kf(p);
funE=@(t)(1-(k^2)*(sin(t)).^2).^(0.5);
Ef=@(x)integral(funE,0,x);
E(i,n) = Ef(p);
end
end
[ka,pa] = meshgrid(ka,pa);
%hold on
surf(ka,pa,K);
surf(ka,pa,E);
%hold off
Error says that the dimensions differ (for surf() )
Is there any way to fix this?
Thanks

댓글 수: 4

Mehmed Saad
Mehmed Saad 2020년 5월 1일
it's working fine for me.
set break point at line 19 and see the dimension of ka,pa. for me all the dimensions are 100x100 and surf is working fine.
KSSV
KSSV 2020년 5월 1일
It is working fine for me...I got the marices sizes to be 100*100.
DONGUK KIM
DONGUK KIM 2020년 5월 1일
Sadly this was what I got from including hold on & hold off
Without hold on it returns one of the surfs fine.
Any reason why this might be happening?
Thanks.
KSSV
KSSV 2020년 5월 1일
What are you expecting actually?

댓글을 달려면 로그인하십시오.

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 5월 1일
편집: Ameer Hamza 2020년 5월 1일

0 개 추천

'hold on', fix the view of the axes. You can explicitly specify to see the 3D view. Change the line at the end of your code like this
hold on
view(3) % add this line for 3D view
surf(ka,pa,K);
surf(ka,pa,E);
% shading interp % this line is optional, just to make the surface looks more clear
hold off

카테고리

질문:

2020년 5월 1일

편집:

2020년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by