How to extract specific entries from a matrix?

3 Ansichten (letzte 30 Tage)
Scott Dallas
Scott Dallas am 1 Jul. 2015
Kommentiert: Brendan Hamm am 1 Jul. 2015
Hi there,
I have a 100,001x7 matrix. I want to obtain the exact location of each entry in column 2 that equals a specific number. For example I want to know which rows in column 2 have an entry equal to 5.
Is there a way to do this on Matlab?
Any help is much appreciated, Scott.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 1 Jul. 2015
A = randi(2000,100001,7); % let this is your data
out = find(A(:,2) == 5);
  3 Kommentare
Andrei Bobrov
Andrei Bobrov am 1 Jul. 2015
Like this is:
intr = [4.5,5.5];
out = find(intr(1) <= A(:,2) & intr(2) >= A(:,2));
Brendan Hamm
Brendan Hamm am 1 Jul. 2015
Or you could do something like:
tol = 0.5; % tolerance
idx = abs(A(:,2) - 5) < tol; % logical vector of locations within tolerance
Now the actual values can be extracted with:
A(idx,2)
or the entire row with
A(idx,:)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by