Double to cell conversion difficulties
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a cell array called temp which stores two columns of dates. Each date is currently stored as a char string (eg: 28/12/2808) within a cell. I'd like to convert these to datenumbers for plotting and sorting.However, when I do this:
temp(:,1)=datenum(temp(:,1),'dd/mm/yy');
I get:
"Conversion to cell from double is not possible."
I've tried drinking several cups of coffee but that hasn't helped either. I assume I am missing { } somewhere but I just can't figure out where. num2cell seems to work but it's not very elegant.
댓글 수: 0
답변 (2개)
Bård Skaflestad
2012년 1월 26일
There is a slight misunderstanding in the way you use datenum. Specifically, datenum(temp(:,1),'dd/mm/yy') returns a double for each element in the cell array temp(:,1). However, you cannot directly assign individual double|s to the corresponding element of |temp(:,1).
One way to achieve the (presumably) desired effect is to use the num2cell function like
temp(:,1) = num2cell(datenum(temp(:,1), 'dd/mm/yy'))
but there may be other techniques that solve the larger problem you're trying to solve more directly.
댓글 수: 0
Jan
2012년 1월 26일
When you want to use the date numbers for plotting and sorting, they must be stored as a numerical vector:
temp2(:,1) = datenum(temp(:,1), 'dd/mm/yy');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!