Matrix issue.
Show older comments
This is my code:
X =unifrnd(0,1,1,100);
i=0;
while(i<m<max(size(X)))
if (X(1,i)<=0.2)
X(1,i)= 1;
else X(1,i)=0;
i=i+1;
end
I am trying to use the values obtained from the unifrnd function which i stored using a matrix. I want to convert the values to wither 1 or 0 based on their value being =<0.2 or > 0.2 . However, it just would not work..
Any assistance would be much appreciated.
I am using the school's computer 2010 matlab to code. Quite troublesome as i have to go to school just to program.
Thank you and regards.
Answers (2)
Andrei Bobrov
on 17 Feb 2012
your code
X =unifrnd(0,1,1,15);
i1 = 1;
while i1 <= numel(X)
if X(i1)<=0.2
X(i1)= 1;
else
X(i1)=0;
end
i1=i1+1;
end
this is bad way for MATLAB code
try
X = rand(1,15) <= .2;
Walter Roberson
on 17 Feb 2012
The expression
i<m<max(size(X))
means
(i<m) < max(size(X))
which compares the logical (true/false) result of i<m to the value of max(size(X))
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!