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.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 7월 1일

0 개 추천

A = randi(2000,100001,7); % let this is your data
out = find(A(:,2) == 5);

댓글 수: 3

Scott Dallas
Scott Dallas 2015년 7월 1일
편집: Scott Dallas 2015년 7월 1일
Thanks for your answer.
I used the code and it worked but I now realize that what I really need are entries that are close to but not necessarily equal to the specific number. For example say the number is 5, I want to find all entries within a particular range of 5.
Is there a way to do this?
Best Wishes, Scott.
Like this is:
intr = [4.5,5.5];
out = find(intr(1) <= A(:,2) & intr(2) >= A(:,2));
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,:)

댓글을 달려면 로그인하십시오.

질문:

2015년 7월 1일

댓글:

2015년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by