arrays within for loop

조회 수: 1 (최근 30일)
Hammad Khalid
Hammad Khalid 2019년 12월 1일
편집: KALYAN ACHARJYA 2019년 12월 1일
for k=1:+1:4
S=(1/(k+1))*(m-b*y-m*r);
I=(1/(k+1))*(a*e-(m+r)*i);
y=y+(S*I);
end
I want to store values of S in ascending array and I in descending array then I'll get required y
can anyone help me with this code please.....

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 1일
편집: KALYAN ACHARJYA 2019년 12월 1일
for k=1:4
S(k)=(1/(k+1))*(m-b*y-m*r); % How to get y here?
I(k)=(1/(k+1))*(a*e-(m+r)*i);
end
S=sort(S);
I=sort(I,'descend');
%Now Calculate Y
Or
y=zeros(1,4)
for k=1:4
S(k)=(1/(k+1))*(m-b*y(k)-m*r);
I(k)=(1/(k+1))*(a*e-(m+r)*i);
y(k+1)=y(k)+(S(k)*I(k));
end
S=sort(S);
I=sort(I,'descend');
% Canculate y again % I didnot find any sense here

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by