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.

Antworten (2)

Andrei Bobrov
Andrei Bobrov am 17 Feb. 2012

0 Stimmen

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
Walter Roberson am 17 Feb. 2012

0 Stimmen

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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Feb. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by