Extracting data in a range

2 Ansichten (letzte 30 Tage)
Asif Rashid
Asif Rashid am 28 Jun. 2021
Kommentiert: Star Strider am 28 Jun. 2021
Hello all,
Suppose I have the following matrix 'A':
[0.1, 2, 83, 1000;
0.4, 3, 79, 1001;
0.2, 4, 91, 1018;
0.3, 5, 75, 1095]
And I want to extract a matrix B, from matrix A where the value of element of third coulum is between 70 and 80. So Matrix B would be:
[0.4, 3, 79, 1001;
0.3, 5, 75, 1095]
Thanks!

Akzeptierte Antwort

Star Strider
Star Strider am 28 Jun. 2021
Try this —
format short g
A = [0.1, 2, 83, 1000;
0.4, 3, 79, 1001;
0.2, 4, 91, 1018;
0.3, 5, 75, 1095];
B = A(A(:,3)>=70 & A(:,3)<=80,:)
B = 2×4
0.4 3 79 1001 0.3 5 75 1095
It creates a logical vector to address the appropriate rows, then copies all the respective columns to ‘B’.
.
  2 Kommentare
Asif Rashid
Asif Rashid am 28 Jun. 2021
Thanks. Appreciate it.
Star Strider
Star Strider am 28 Jun. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by