Copy part of an cell array(double) into a new column next to it
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Kelly Kearney
2014-3-18
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 个评论
Kelly Kearney
2014-3-18
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.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!