フィルターのクリア

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

9 ビュー (過去 30 日間)
Blake
Blake 2024 年 9 月 3 日
編集済み: Jatin 2024 年 9 月 4 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by