Z must be a matrix, not a scalar or vector

조회 수: 3 (최근 30일)
Kundan Prasad
Kundan Prasad 2021년 8월 17일
댓글: Kundan Prasad 2021년 8월 19일
clc
clear all
R=10;
f=0.5;
s=50;
N=36;
a=f/(s*N);
Ax=0.002;
Ay=0.002;
lx=2.5;
ly=2.5;
n=((R*s*N)/f)+1;
for i=1:n
r(i)=(R-((i-1)*a));
theta(i)= ((i-1)*(2*pi/N));
x(i)=(r(i)*cos(theta(i)));
y(i)=(r(i)*sin(theta(i)));
[xx(i),yy(i)]=meshgrid(x(i),y(i));
Z(i)=((Ax*cos(2*pi*xx(i)/lx))+(Ay*cos(2*pi*yy(i)/ly)));
end
surf(xx,yy,Z);
  댓글 수: 2
Yazan
Yazan 2021년 8월 17일
You forgot to ask a question.
Kundan Prasad
Kundan Prasad 2021년 8월 17일
I want 3d plot and every time i am getting an error that Z must be a matrix, not a scalar or vector

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

채택된 답변

Matt J
Matt J 2021년 8월 17일
편집: Matt J 2021년 8월 17일
R=10;
f=0.5;
s=50;
N=36;
a=f/(s*N);
Ax=0.002;
Ay=0.002;
lx=2.5;
ly=2.5;
n=((R*s*N)/f)+1;
for i=1:n
r(i)=(R-((i-1)*a));
theta(i)= ((i-1)*(2*pi/N));
x(i)=(r(i)*cos(theta(i)));
y(i)=(r(i)*sin(theta(i)));
% [xx(i),yy(i)]=meshgrid(x(i),y(i));
Z(i)=((Ax*cos(2*pi*x(i)/lx))+(Ay*cos(2*pi*y(i)/ly)));
end
T=delaunayTriangulation(x(:),y(:));
trisurf(T.ConnectivityList,x(:),y(:),Z(:),'EdgeColor','none','FaceAlpha',0.6);
view(-80,75)
  댓글 수: 4
Kundan Prasad
Kundan Prasad 2021년 8월 17일
thank you it worked
Matt J
Matt J 2021년 8월 17일
You're welcome, but please Accept-click the answer to indicate that it worked.

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

추가 답변 (1개)

Kundan Prasad
Kundan Prasad 2021년 8월 18일
R=10;
f=0.5;
s=50;
N=100;
a=f/(s*N);
Ax=2;
Ay=2;
lx=2.5;
ly=2.5;
n=((R*s*N)/f)+1;
r(0)=0;
Z(0)=0;
t=0.5;
for i=1:n
r(i)=(R-((i-1)*a));
theta(i)= ((i-1)*(2*pi/N));
x(i)=(r(i)*cos(theta(i)));
y(i)=(r(i)*sin(theta(i)));
Z(i)=((Ax*cos(2*pi*x(i)/lx))+(Ay*cos(2*pi*y(i)/ly)));
m(i) = ((Z(i-1) - Z(i))./(r(i-1)-r(i)));
newth(i) = atan(-m(i));
G(i)=r(i)-(t*sin(newth(i)));
H(i)=Z(i)+(t*cos(newth(i)))-t; %% THE compensate value of r1 and Z1
% needed to calculate from the previous value of r(i) and Z(i)
end
T=delaunayTriangulation(x(:),y(:));
trisurf(T.ConnectivityList,x(:),y(:),Z(:),'EdgeColor','none','FaceAlpha',0.6);
view(-80,75)
I am unable to calculate the value of G and H from the previous value of r(i) and Z(i). Can you please check the code. Thank you
  댓글 수: 10
Walter Roberson
Walter Roberson 2021년 8월 19일
R=10;
f=0.5;
s=50;
N=100;
a=f/(s*N);
Ax=2;
Ay=2;
lx=2.5;
ly=2.5;
n=((R*s*N)/f)+1;
roff = 1;
Zoff = 1;
r(0+roff)=0;
Z(0+Zoff)=0;
t=0.1;
Pi = (pi);
for i=1:n
r(i+roff)=(R-((i-1)*a));
theta(i)= ((i-1)*(2*Pi/N));
x(i)=(r(i+roff)*cos(theta(i)));
y(i)=(r(i+roff)*sin(theta(i)));
Z(i+Zoff)=((Ax*cos(2*Pi*x(i)/lx))+(Ay*cos(2*Pi*y(i)/ly)));
m(i) = ((Z(i-1+Zoff) - Z(i+Zoff))./(r(i-1+roff)-r(i+roff)));
newth(i) = atan(-m(i));
G(i)=r(i+roff)-(t*sin(newth(i)));
H(i)=Z(i+Zoff)+(t*cos(newth(i)))-t; %% THE compensate value of G and H
% needed to calculate from the previous value of r(i) and Z(i)
end
T=delaunayTriangulation(x(:),y(:));
trisurf(T.ConnectivityList,x(:),y(:),H(:),'EdgeColor','none','FaceAlpha',0.6);
view(-80,75)
Kundan Prasad
Kundan Prasad 2021년 8월 19일
Thank you, now its working

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by