Click here to Skip to main content
16,015,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
New programmer here,

I got a task to make a program that picks and displays number of numbers greater than 0.8 in a random matrix 5x6 with 2 for loops and would appreciate help if someone knows how to make it.

Thanks in advance.

this is how the code starts:

clear

clc

rand(5,6);

for row =….


What I have tried:

I tryed few things with no results
Posted
Updated 4-Nov-20 12:14pm

1 solution

[0.91, 0.81, 0.72, 0.74, 0.33, 0.85]
[0.91, 0.81, 0.72, 0.74, 0.33, 0.85]
[0.91, 0.81, 0.72, 0.74, 0.33, 0.85]
[0.91, 0.81, 0.72, 0.74, 0.33, 0.85]
[0.91, 0.81, 0.72, 0.74, 0.33, 0.85]



now iterate through each row and each column

for row = 0 to 4
   for column = 0 to 5
        if (columnVal > 0.8)  printLine "{row} : {column}"
   next column
next row


You should see something like :
0 : 0
0 : 1
0 : 5
...


row 0, column 0 is greater than
row 0, column 1 is great than

Just convert it to your matlab code.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900