I have 2 cell arrays
A= n01944390
n01984695
n02056570
n02058221
n02099601
n02099712
B = n15296258 octave
n15296354 then
n15296489 shiva, shivah, shibah
n15296687 epoch, date of reference
n15296920 clotting time
n15297069 rotational latency, latency
n15297303 probation
n15297472 probation
n15297672 processing time
n15297859 air alert
I need to compare the first column if these 2 cell arrays and if they are equivalent, add the row of the matrix B to the equivalent row of matrix A
I wrote this for loop
for i=1:length(A)
if A(i) == B (i,1)
A(i,2) = B(i,2);
A(i,3) = B (i,3);
end
end
but it gives me this error message "Undefined function 'eq' for input arguments of type 'cell'."
Can anyone help me?

 Akzeptierte Antwort

Guillaume
Guillaume am 11 Nov. 2016

0 Stimmen

The notation in your question is incomprehensible. Please use valid matlab syntax (and the {} Code button to format text as code).
Anyway, if I understood correctly what you want:
[isfound, whichBrow] = ismember(A(:, 1), B(:, 1)); %find which keys of A are in the keys of B
newA = [A, cell(size(A, 1), size(B, 2)-1)]; %add columns to A to receive the columns of B
newA(isfound, 2:end) = B(whichBrow(isfound), 2:end) %and copy columns that matched

1 Kommentar

Rehab Ali
Rehab Ali am 11 Nov. 2016
Bearbeitet: Rehab Ali am 11 Nov. 2016
Thank you sooooooooooo much
It solvs my problem :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 11 Nov. 2016

Bearbeitet:

am 11 Nov. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by