When using find function, if function find is a empty matrix how to change that value?

I have two matrices (A and B) and I am comparing elements in matrix A to elements in matrix B. If there is a match A(i,j,k)==B matrix f will take value 1. If there is no match f will take value 0:
A = [5 7; 0 1]; A(:,:,2) = [1 0; 3 5]; B = [5 3; 0 7]; B(:,:,2) = [3 0; 3 3]; f=zeros(size(A)); for i = 1:size(A) for j = 1:size(A) for k = 1:size(A) [x,y,z] = ind2sub(sE,find(A(i,j,k)==B)); if x == zeros(0,1) f(i,j,k) = 0; else f(i,j,k) = 1; end end end end
I am having a error in if: ??? Error using ==> eq Matrix dimensions must agree.
How can I solve this?

3 件のコメント

Jan
Jan 2012 年 10 月 31 日
Please learn how to format code in this forum. It has been explained repeatedly.
Daniyal Awan
Daniyal Awan 2012 年 10 月 31 日
Hi, Use 'preview' option to see how others see your post.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 10 月 31 日

0 投票

Use isempty() to detect empty matrices rather than comparing to an empty matrix.

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

Ana
2012 年 10 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by