How can I compare two cell arrays with different sizes ?

10 visualizaciones (últimos 30 días)
Farnaz Baya
Farnaz Baya el 23 de Ag. de 2022
Comentada: Farnaz Baya el 23 de Ag. de 2022
I have two cell arrays: a and b
a = {{1,1} ,{2,3} ,{4,5},{6,7} ,{8,9} ,{10,11};{12,13} ,{14,15} ,{16,17},{18,19} ,{20,21} ,{22,23}};
b = {{1,1} ,{4,5},{16,17}};
I want to compare each inner cells of a and b (a and b are of different sizes) and if they are the same, MATLAB returns 1 if yes and 0 if no in cell a :
a = [1 , 0 ,1 , 0 , 0 , 0 ; 0 , 0 , 1, 0,0,0];

Respuesta aceptada

Rik
Rik el 23 de Ag. de 2022
A simple loop will do the trick:
a = {{1,1} ,{2,3} ,{4,5},{6,7} ,{8,9} ,{10,11};{12,13} ,{14,15} ,{16,17},{18,19} ,{20,21} ,{22,23}};
b = {{1,1} ,{4,5},{16,17}};
out=false(size(a));
for n=1:numel(a)
for m=1:numel(b)
if isequal(a{n},b{m})
out(n)=true;
break
end
end
end
out
out = 2×6 logical array
1 0 1 0 0 0 0 0 1 0 0 0

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by