compare elements of cell and 2D array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
lucksBi
el 4 de Abr. de 2017
Comentada: lucksBi
el 4 de Abr. de 2017
Hey I have a 2D array like
a=[0 0 3 4 0 0; 1 0 3 4 0 0]
and a cell array like
b(1,1)=[0 2 0 0 0 0; 1 2 3 4 0 0]
b(2,1)=[0 0 3 4 0 0; 0 2 0 0 0 0; 1 2 3 4 0 0]
For each non zero element in each row of a, it should search the element in corresponding cell array and display row index at where it is present. e.g for 3 in first row, it will search in b(1,1) and display 2 (as 3 is present at 2nd row) and e.g. for 4 in 2nd row it will search in b(2,1) and display 1 and 3.
Thanks in advance.
0 comentarios
Respuesta aceptada
ranjith kumar reddy P
el 4 de Abr. de 2017
a=[0 0 3 4 0 0; 1 0 3 4 0 0];
b{1,1}=[0 2 0 0 0 0; 1 2 3 4 0 0];
b{2,1}=[0 0 3 4 0 0; 0 2 0 0 0 0; 1 2 3 4 0 0];
NZelem = find(a);
for i = 1:length(NZelem)
c = a(NZelem(i));
d1 = find(b{1,1}==c);
r1 = rem(d1,2);
if(r1==0)
printf('the element %d in b{1,1} is in row %d',c,2);
else
printf('the element %d in b{1,1} is in row %d',c,1);
end
d2 = find(b{2,1}==c);
r2 = rem(d2,2);
if(r2==0)
printf('the element %d in b{2,1} is in row %d',c,2);
else
printf('the element %d in b{2,1} is in row %d',c,1);
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!