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.
You've made a slight error in the comparisons, but as this is most likely homework, I would leave it as is and let the OP figure it out (and best would have been not to provide the loop method, they won't learn anything if you do their homework).
@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.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/351047-how-to-use-if-and-for-random-matrices#comment_473485
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/351047-how-to-use-if-and-for-random-matrices#comment_473485
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/351047-how-to-use-if-and-for-random-matrices#comment_473513
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/351047-how-to-use-if-and-for-random-matrices#comment_473513
Sign in to comment.