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')

Answers (1)

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?

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 20 Mar 2017

Answered:

on 20 Mar 2017

Community Treasure Hunt

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

Start Hunting!