How can I create a matrice with values over a number of this matrix ?

1 view (last 30 days)
I have data of more than 18'000 earthquakes and I need to code a "for" loop that can find how many earthquakes >=7 occured.
I know how to use the loop, but I've no clue how to create a new matrice with all the earthquakes over 7 + a lign that counts them.
Thanks in advance !

Answers (1)

Star Strider
Star Strider on 19 Apr 2023
Perhaps something like this —
earthquakes = rand(20,1)*9 % Data (Richter Magnitudes)
earthquakes = 20×1
6.8914 8.6107 1.5547 8.8077 5.7766 2.5438 2.9706 7.1412 1.5764 8.5690
eq_gt7 = earthquakes>7 % Logical Vector
eq_gt7 = 20×1 logical array
0 1 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0
Nr_earthquakes_gt7 = nnz(eq_gt7) % Number Of Earthquakes > 7
Nr_earthquakes_gt7 = 6
earthquakes_gt7 = earthquakes(eq_gt7) % Magnitudes Of Earthquakes > 7
earthquakes_gt7 = 6×1
8.6107 8.8077 7.1412 8.5690 7.7133 8.7649
.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!