r=[0.5,1,1.5....5]; theta= linspace(0,2*pi,73); [theta,r]=meshgrid(theta,r); [x11,y11]=pol2cart(theta,r); x1= x11(:);
% I have a function z whose input needs to be x and y between [-1,1] so I need to change x and y both %such that for x1>1, x=1, x1<-1, x=-1 and -1<=x1<=1, x=x1 % i tried this for k=1:length(x1) if x1(k)<-1 x(k)=-1 else if x1(k)>=-1 && x1(k)<= 1 x(k)=x1 else if x1(k)>1 x(k)=1 end end
z= 1.3249-.004937*x+5.43243*x.^2-1.153*x.*3+4.2693*y.^6 % Repeating same for Y as well. when I run this i get In an assignment A(I)=B and I must be same. Is anyone able to help me. Thanks in advance

 채택된 답변

Saagar
Saagar 2014년 9월 16일

0 개 추천

for k=1:length(x1)
if x1(k)<-1
x(k)=-1
elseif x1(k)>=-1 && x1(k)<= 1
x(k)=x1(k)
else x1(k)>1
x(k)=1
end
end
Sorry, didn't realize I didn't have the "code" option selected, should be easier to read now. The problem you are getting is because you are currently trying to make x(k)=x1, but x1 is currently a vector, and you only need the corresponding element x1(k).
Hope this helps.

댓글 수: 2

sagar pokhrel
sagar pokhrel 2014년 9월 17일
I used same for x and y and ran the code but it just gave me single output instead of length (x1)( 730). How do i run code for each 830 x and corresponding Y to get 830 output
Thanks in advance
Saagar
Saagar 2014년 9월 17일
any chance that you could post the code you used? it would make it easier to follow what you are asking

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Desktop에 대해 자세히 알아보기

질문:

2014년 9월 16일

댓글:

2014년 9월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by