output from an if statment
이전 댓글 표시
i'm trying to take the output from an if statement inside a for loop in an array but the values are getting overwritten here is my code
% clc
clear
n=input('enter number of variables: ');
r=input('please enter the limit: ');
z = cell(1,n);
y = zeros(1,n);
f = zeros(1,n);
for i=1:n
z{i}=input('enter the variable name: ','s');
y(i)=input('assign a number to this variable: ');
f(i)=input('second variable: ');
end
[ys,j]=sort(y,'descend');
fs=f(j);
zs=z(j);
k=n;
for l=1:n
if fs(l)>r
disp('This mud type can not be used')
disp(zs(l))
fx=length(fs(l));
zn=cell(1,fx);
zn(l)=zs(1);
end
end
input('end')
답변 (1개)
James Tursa
2017년 3월 20일
These statements:
zn=cell(1,fx);
zn(l)=zs(1);
The first statement above wipes out any previous values/cells you had assigned to the variable zn and replaces it the a cell array containing empty cells. So you need to rewrite this code. What exactly do you want saved each iteration?
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!