How to use If and for Random Matrices???

조회 수: 1 (최근 30일)
Ahamed KMR
Ahamed KMR 2017년 8월 1일
다시 열림: Ahamed KMR 2018년 7월 19일
generate a 5*8 matrix of random numbers and next write a programme using "for" and "if" loops to replace numbers less than 0.5 with "0" and numbers 0.5 or above with 1.
  댓글 수: 2
KSSV
KSSV 2017년 8월 1일
Seems this is an Home Work....such a easy task...what have you tried?
Jan
Jan 2017년 8월 1일
There are no "if loops", to be correct.

댓글을 달려면 로그인하십시오.

답변 (1개)

H ZETT M
H ZETT M 2017년 8월 1일
So the way without the for and if loops is:
X=rand(5,8)
X(X<(0.5))=0;
X(X>(0.5))=1;
if you really want to use loops:
X=rand(5,8)
for i=1:5
for m=1:8
if X(i,m)<=0.5
X(i,m)=0;
else X(i,m)=1;
end
end
end
  댓글 수: 4
Ahamed KMR
Ahamed KMR 2017년 8월 1일
Hello H ZETT M,
First of all thanks for your quick response.
Once i run the code, it shows only the random matrix. Did you miss something???
I await your prompt action.
Have a nice day:) Thank you!
Jan
Jan 2017년 8월 1일
@Ahamed KMR: You are waiting H ZETT M's prompt action?! This sounds rather impolite considering the fact, that he or she has almost solved your homework. The remaining work to do is really tiny, so please do show any own effort.
Posting homework solutions is a drawback for the reputation of the forum. In my university posting solutions programmed by others without mentioning this clearly was treated as cheating and one can loose the status as student.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by