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

3 views (last 30 days)
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.

Answers (3)

Matt J
Matt J on 3 Sep 2024
Edited: Matt J on 3 Sep 2024
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 Comments
Blake
Blake on 3 Sep 2024
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 on 3 Sep 2024
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..

Sign in to comment.


Jatin
Jatin on 3 Sep 2024
Edited: Jatin on 4 Sep 2024
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 on 3 Sep 2024
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)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!