How to apply efficient if-else statements in a big data cell array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a cell array of 3 columns. Based on the different joint values of 2nd and 3rd columns, I would like to assign a number to the values of first column. for example:
a x z
b y z
c x y
d y z
for x&z I assign 1 to a, for y&z I assign 2 to b and d, for x&y I assign 3 to c. Well, I can do it within a for-loop and some if-else statements. But the document is too big and this is a bit slow. Does anyone know about an efficient and fast way to do it so?
Many thank, Shima
1 comentario
Respuestas (1)
Jos (10584)
el 25 de Mzo. de 2016
Editada: Jos (10584)
el 25 de Mzo. de 2016
It is a cell array, but each cell has a single number? Then you might be better of converting it to numbers first:
N = cell2mat(C) ;
N(N(:,2)==x & N(:,3)==z, 1) = 1 ;
N(N(:,2)==y & N(:,3)==z, 1) = 2 ;
N(N(:,2)==x & N(:,3)==y, 1) = 3 ;
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!