How to compare betwen two cells?

3 visualizzazioni (ultimi 30 giorni)
Mira le
Mira le il 19 Nov 2019
Commentato: Ridwan Alam il 22 Nov 2019
How to compare betwen two cells? like this:
S and T1 are two cell with different values:
c=1:
i=1;
SI{c},T1{i}
the error "Cell contents reference from a non-cell array object." appear
what is the suitble command matlab to use?
  3 Commenti
Mira le
Mira le il 19 Nov 2019
Modificato: dpb il 19 Nov 2019
S is cell intialised as
S= {1 2 , 2 3}
T1 also a cell
like
T1{1} = 1 2 3
T1{2} = 1 2 4
T1{4} = 1 2 3 5
S{1} = 1 2
S{2} = 2 3
each S{i} exist in T1{j}
dpb
dpb il 19 Nov 2019
The above is simply not so as written--
>> S= {1 2 , 2 3}
S =
1×4 cell array
{[1.00]} {[2.00]} {[2.00]} {[3.00]}
>> whos S
Name Size Bytes Class Attributes
S 1x4 480 cell
>> S{1}
ans =
1.00
>> S{2}
ans =
2.00
>> T1{1} = 1 2 3
T1{2} = 1 2 4
T1{4} = 1 2 3 5
T1{1} = 1 2 3
Error: Unexpected MATLAB expression.
So the T1 can't be...could write something like:
>> T1{1} = [1 2 3]
T1 =
1×1 cell array
{1×3 double}
>> S{T1{1}}
ans =
1.00
ans =
2.00
ans =
2.00
>>
returns each element indexed into S but in a comma-separated list. This can be consolidated by surrounding with braces as:
>> [S{T1{1}}]
ans =
1.00 2.00 2.00
>>
Or, you can return the elements as cell array if don't dereference S but only T1:
>> S(T1{1})
ans =
1×3 cell array
{[1.00]} {[2.00]} {[2.00]}
>>
As requested before, we need to know precisely what storage form you do have; what you've posted simply doesn't work as written.
That's why asked for the output from the whos command--it shows what exists unequivocally.

Accedi per commentare.

Risposta accettata

Ridwan Alam
Ridwan Alam il 19 Nov 2019
Modificato: Ridwan Alam il 20 Nov 2019
T1{1} = [1 2 3];
T1{2} = [1 2 4];
T1{4} = [1 2 3 5];
S{1} = [1 2];
S{2} = [2 3];
%
%
setdiff(cell2mat(T1),cell2mat(S))
% ans =
%
% 4 5
Please accept the answer if it works!
  1 Commento
Ridwan Alam
Ridwan Alam il 22 Nov 2019
Hi Mira,
If this solution works, please accept as an answer.
If there is anything wrong, please let me know.
Thanks!!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by