필터 지우기
필터 지우기

Simply trying to find a value in the same row as my known value but in a different column.

조회 수: 9 (최근 30일)
I have a 225x3 matrix and I have a known value somewhere in column 1. How do I find the value that is in the same row as my known value but in column 3? Everything I have tried also gives me an answer of "0×1 empty double column vector," but without any value.
I would also like to know how to simply just find what row my value is in, but everything I have tried for that also gives me the same "0×1 empty double column vector" answer.

답변 (3개)

Matt J
Matt J 2024년 9월 3일
편집: Matt J 2024년 9월 3일
Everything I have tried also gives me an answer of "0×1 empty double column vector," but without any value.
You haven't shown us what you've tried, but my guess is that you've ignored floating point precision errors when testing for equality with your value. Calling your matrix A, one solution might be,
rows=find(abs(A(:,1)-value)<1e-6);
A( rows, 3)
  댓글 수: 2
Blake
Blake 2024년 9월 3일
Even by using this and the solution by Jatin Singh below has still both returned me with the message "rows = 0×1 empty double column vector."
Matt J
Matt J 2024년 9월 3일
Well, attach the matrix in a .mat file and run your code for us. We still have no visual picture what you are doing or what your data looks like..

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


Jatin
Jatin 2024년 9월 3일
편집: Jatin 2024년 9월 4일
Hi @Blake,
If you want to obtain the index of a specific value in your matrix, you can use the "find" function, which returns the indices of each entry that matches the specified value.
In your case you can use the below code to get the indices of values matching with "value" in column 1 of a matrix 'A'.
Indices = find(A(:,1) == value);
To get the corresponding values in column 3 in the matrix you can use:
col3Values = A(Indices, 3);
Please note that the "find" function returns a list of indices for all matching values. If you want to obtain only the first or last occurrence of a value, you can specify the direction using the 'first' or 'last' keyword.
kindly follow the documentation below for more information on "find" function:
Hope this helps!

Walter Roberson
Walter Roberson 2024년 9월 3일
rows = ismembertol( A(:,1), value);
A( rows, 3)
If this does not work, then either A(:,1) is not the same datatype as value, or else value does not appear approximately in A(:,1)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by