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!