Copy part of an cell array(double) into a new column next to it
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hey
so i have some data in a column which is of type double. an example:
V
___
231
234
232
230
229
... etc.
so what i want to do is, to make the matlab sort the values over 230 into a new column so it looks like this: _ _ 231 231 234 234 232 232 230 0 229 0 ... etc.
i Wrote this code: V(:,2) = V(:,1) > 230; i obtained the result, but in the second column i get 1 on the places with values over 230 and 0 in the places with values lower than 230..
Suggestion of why and what i can do?.. this only works when the Cell is double...if i change it to string..it will display error and say something about 'gt' etc.
thanks in advance
0 comentarios
Respuestas (1)
Kelly Kearney
el 18 de Mzo. de 2014
V = [...
231
234
232
230
229];
V(:,2) = 0;
V(V(:,1)>230,2) = V(V(:,1)>230,1)
Results:
V =
231 231
234 234
232 232
230 0
229 0
Not sure what you mean about the string... you can only do numerical comparisons on numbers (double, int, logical, etc), not strings, so the error makes sense. If your data begins as a cell array of strings, you'll have to convert it first.
2 comentarios
Kelly Kearney
el 18 de Mzo. de 2014
Not at all clear what you mean... how about an example?
(And make sure you format your post; right now I'm not sure if you really want row-vector output or if you're just failing to format what you're typing.)
Ver también
Categorías
Más información sobre Logical 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!