Substitute blank entries in a cell array by elements from a double matrix

1 visualización (últimos 30 días)
I have a cell type variable A with 500 rows and 3 columns:
c1 y v c1 c2 c3
A={13 1999 47,7 13 183 [] [] 0
141 1999 60,2 141 308 [] [] 0
174 1999 51,9 174 308 [] [] 0
181 1999 52,9 181 183 [] [] 0}
And I have a double variable B with 2000 rows and 3 columns:
y c1 c3
B=[1999 13 32
1999 67 189
1999 140 40
1999 141 55
1999 143 53
1999 174 38
1999 177 63
1999 181 30
1999 185 51]
If the first column of A matches the second column of B (if the c1s match in A and B) then I would like to substitute the blank entries [ ] in the sixth column of A (c3) by the values of the third column of B (c3). So my new A:
A={13 1999 47,7 13 183 32 [] 0
141 1999 60,2 141 308 55 [] 0
174 1999 51,9 174 308 38 [] 0
181 1999 52,9 181 183 30 [] 0}
Thank you

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Ag. de 2014
Editada: Azzi Abdelmalek el 12 de Ag. de 2014
A={13 1999 47.7 13 183 [] [] 0
141 1999 60.2 141 308 [] [] 0
174 1999 51.9 174 308 [] [] 0
181 1999 52.9 181 183 [] [] 0}
B=[1999 13 32
1999 67 189
1999 140 40
1999 141 55
1999 143 53
1999 174 38
1999 177 63
1999 181 30
1999 185 51]
[ii,jj]=ismember(B(:,2),[A{:,1}]')
A(nonzeros(jj),6)=num2cell(B(ii,3))

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 12 de Ag. de 2014
c = cell2mat(A(:,4));
A(:,6) = num2cell(B(ismember(B(:,2),c),3));

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by