フィルターのクリア

Compare values of array of matrix 5x5x106

1 回表示 (過去 30 日間)
pamela sulis
pamela sulis 2015 年 11 月 20 日
編集済み: Thorsten 2015 年 11 月 20 日
Hi!
I have a array of logical matrix 5x5x106 (attached file): I want to compare every logical matrix with the others to find common elements end save them. I try this code:
for k=1:106
if valueNoZeros(:,:,k)==valueNoZeros(:,:,k+1)
a(:,:,k)=1;
end
end
and also this
for k=1:106
if valueNoZeros(:,:,k)==valueNoZeros(:,:,k+1)
for i=1:5
for j=1:5
a(i,j,k)=1;
end
end
end
end
but it gives me an error: 'Conversion to cell from double is not possible'
Can you help me?

採用された回答

Thorsten
Thorsten 2015 年 11 月 20 日
編集済み: Thorsten 2015 年 11 月 20 日
If you want to compare every matrix with each other, you have 5565 pairs to compare:
Npairs = nchoosek(1:106,2);
N = size(Npairs, 1);
A = zeros(5,5,N);
for i = 1:N
A(:,:,i) = valueNoZeros(:,:,Npairs(i,1)) == valueNoZeros(:,:,Npairs(i,2));
end
If you just want to compare a matrix with the following matrix, you have 105 comparisons:
N = 106 - 1;
for i = 1:N
A(:,:,i) = valueNoZeros(:,:,i) == valueNoZeros(:,:,i+1);
end
  2 件のコメント
pamela sulis
pamela sulis 2015 年 11 月 20 日
編集済み: pamela sulis 2015 年 11 月 20 日
I have a doubt: I want to compare only the values '1' and not the '0', I modify your code in this way:
Npairs = nchoosek(1:106,2);
N = size(Npairs, 1);
A = zeros(5,5,N);
for i = 1:N
if (valueNoZeros~=0)
A(:,:,i) = valueNoZeros(:,:,Npairs(i,1)) == valueNoZeros(:,:,Npairs(i,2));
end
end
but now the comparison give me matrix of all zeros: isn't correct the command 'if (valueNoZeros~=0)'? I have thought that with this command, the code doesn't consider values '0' but only the '1'.
Thorsten
Thorsten 2015 年 11 月 20 日
編集済み: Thorsten 2015 年 11 月 20 日
valueNoZeros~=0 gives an 5x5x106 logical array that is logical 1 if valueNoZeros is one (valueNoZeros~=0) else 0. So this is just the same as valueNoZeros! Moreover, it is a whole array, which is only true if all elements are true; in the example, it is never true...
So if you want A to be 1 if there is a one in two matrices, use
A(:,:,i) = valueNoZeros(:,:,Npairs(i,1)) & valueNoZeros(:,:,Npairs(i,2));

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by