フィルターのクリア

returning a unique array and comparing it with a different array.

2 ビュー (過去 30 日間)
Tony Haines
Tony Haines 2024 年 1 月 31 日
コメント済み: Tony Haines 2024 年 2 月 13 日
Hello,
I have a code that generates the y-coordinates of a few points, and returns the matrix as follows.
y_cosnode =
0.5833 0.6667 0.7500 0.8333 0.9167 1.0000
0.5000 0.5833 0.6667 0.7500 0.8333 0.9167
I wanted non-repeating values so I used y_cosnode = reshape(unique(y_cosnode),1,[]) . This gives me
y_cosnode =
0.5000 0.5833 0.6667 0.7500 0.8333 0.9167 1.0000
Now, I have another matrix array, a = [0.5000 0.5833 0.6667 0.7500 1] which I would like to compare each entry values with y_cosnode.
for i=1:size(y_cosnode,2)
[row,col] = find(y_cosnode(1,i)==a(1,:));
col
end
col =
1
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
4
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
5
obviously, 0.5833 and 0.6667 should not be empty because they are in matrix a. However, when I replace the matrix array 'y_cosnode', with
y_cosnode = [0.5000 0.5833 0.6667 0.7500 0.8333 0.9167 1.0000] which are the same values, just typed by myself, I get the following results. Which is what I'm looking for.
col =
1
col =
2
col =
3
col =
4
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
5
  1 件のコメント
Matt J
Matt J 2024 年 2 月 1 日
編集済み: Matt J 2024 年 2 月 1 日
0.5833 and 0.6667 should not be empty because they are in matrix a.
They are probably not in fact in matrix a. You're only displaying these numbers to 4 decimal places, so we cannot verify that the numbers agree beyond that.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2024 年 2 月 1 日
編集済み: Matt J 2024 年 2 月 1 日
The whole thing can be done in one line. No need for unique, reshape, or any of the rest of it.
result = ismembertol(a,y_cosnode(:),1e-6)
And if a nonlogical indices are really needed, you can add,
find(result)
  1 件のコメント
Tony Haines
Tony Haines 2024 年 2 月 13 日
Thank you for your suggestion. All i needed was to add a tolerance value.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by