From: alfann on
Dear collegues,
If I have this matrix:
U1=[0 1 0 0 3; 0 0 0 0 0; 0 0 1 0 0; 0 3 0 0 0; 0 0 0 5 0; 0 0 0 0 3]
and we see 1 and 3 are in the first row but 3 is only in the last row.
I want to check:
if the same number in the first row of the matrix (except zero 0) is found in the last row of the matrix (except zero 0), the value of this variable (Result_matrix=1).
How can I do that please?
From: Jos (10584) on
alfann <alfann.net(a)hotmail.com> wrote in message <1476671741.303915.1276080883937.JavaMail.root(a)gallium.mathforum.org>...
> Dear collegues,
> If I have this matrix:
> U1=[0 1 0 0 3; 0 0 0 0 0; 0 0 1 0 0; 0 3 0 0 0; 0 0 0 5 0; 0 0 0 0 3]
> and we see 1 and 3 are in the first row but 3 is only in the last row.
> I want to check:
> if the same number in the first row of the matrix (except zero 0) is found in the last row of the matrix (except zero 0), the value of this variable (Result_matrix=1).
> How can I do that please?

Combine ANY, ISMEMBER and NONZEROS, as in

any(ismember(nonzeros(U1(1,:)),nonzeros(U1(end,:))))

Jos
From: Jos (10584) on
alfann <alfann.net(a)hotmail.com> wrote in message <1476671741.303915.1276080883937.JavaMail.root(a)gallium.mathforum.org>...
> Dear collegues,
> If I have this matrix:
> U1=[0 1 0 0 3; 0 0 0 0 0; 0 0 1 0 0; 0 3 0 0 0; 0 0 0 5 0; 0 0 0 0 3]
> and we see 1 and 3 are in the first row but 3 is only in the last row.
> I want to check:
> if the same number in the first row of the matrix (except zero 0) is found in the last row of the matrix (except zero 0), the value of this variable (Result_matrix=1).
> How can I do that please?

and if they non-zero values need to be in the same spots as well

any(U1(1,:) == U1(end,:) & (U1(1,:) * U1(end,:)))

Jos