Copy part of an cell array(double) into a new column next to it
2 ビュー (過去 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!