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.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 2월 17일

0 개 추천

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 2012년 2월 17일

0 개 추천

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

카테고리

도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2012년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by