Find the equality of each value in the vector and cell array

3 ビュー (過去 30 日間)
NA
NA 2020 年 11 月 9 日
コメント済み: NA 2020 年 11 月 10 日
I have
A = {1;[];1;[]};
B = [1;4;10;4];
I want to check equality of each row in the cell to the each row in the array and find the index. I use this code, but it is not correct.
temp = zeros(length(B),1);
for i=1:length(B)
if isempty(A{i})==0
temp(i) = find(isequal(A{i},B(i)));
else
temp(i) = 0;
end
end
result should be
temp =[1;0;0;0]
  1 件のコメント
Sindar
Sindar 2020 年 11 月 9 日
Please include any error messages in your question

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

採用された回答

Sindar
Sindar 2020 年 11 月 9 日
% better test data
A = {1;[];1;[1 4];3};
B = [1;4;10;4;3];
temp = zeros(length(B),1);
for i=1:length(B)
% isequal handles empty cells, cells with multiple elements, non-numeric contents, etc.
if isequal(A{i},B(i))
temp(i)=i;
end
end
temp
temp =
1
0
0
0
5

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by