0
votes

I have some difficulties with matlab, I can not get a comparison of cells with values

I have a variable IN of 1x14 cells, each cell can have a string or an array of values, and each cell has a different length

example string of

IN(1,1) = '1,2,3,8,10,11,12,'

example array of

IN(1,2) = [1x10 double]

meaning in IN(1,2) I have 10 cells and each cell with a value 1 2 3 7 9 10 11 12 13 14

so IN(1,1) has 7 values and IN(1,2) has 10

................

assuming I am using only arrays like

IN(1,1) I have 7 cells and each cell with a value 1 2 3 8 10 11 12

IN(1,2) I have 10 cells and each cell with a value 1 2 3 7 9 10 11 12 13 14

I want to know which values of IN(1,1) can be found in IN(1,2) in this case, IN(1,2) is member of IN(1,1) in 1 2 3 10 11 12

................

or if they are strings

IN(1,1) = '1,2,3,8,10,11,12,'

IN(1,1) = '1,2,3,7,9,10,11,12,14,'

How do I compare them and retrieve these common values?

I do not know whether I should use strings or arrays of values.

thanks for your help

1
Are your strings always representing numerical values? - BillBokeey
Also, do you want to fetch the values that are common to every cell of your cell array? - BillBokeey

1 Answers

0
votes

never mind, I had to use nested 'for' loops to compare each value on each cell against the other cells I should have checked the documentation on multilevel access to cells, here is the link https://au.mathworks.com/help/matlab/matlab_prog/multilevel-indexing-to-access-parts-of-cells.html

anyway thanks here my code for multilayer access, comparing cell by cell with all the cells and extracting the common values among them

for(c=1:length(nx))
    NB_V1=IN{1,c};                           
    for cc=1:(length(nx)-c)
        NB_VCC=IN{1,c+cc};   
        display(['comparing database ' num2str(c) ' with ' num2str(cc+c) ])        
        for ccc=1:(length(NB_V1))
            NB_V2=NB_V1(1,ccc);
            for cccc=1:(length(NB_VCC))
                NB_VCC2=NB_VCC(1,cccc);
                if (NB_V2 == NB_VCC2);
                    display(['matching ' num2str(NB_V2) ' between ' num2str(c) ' and ' num2str(cc+c)])        
                end
            end
        end
    end
end