Double to cell conversion difficulties

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.

답변 (2개)

Bård Skaflestad
Bård Skaflestad 2012년 1월 26일

1 개 추천

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.
Jan
Jan 2012년 1월 26일

1 개 추천

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');

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

Joe
2012년 1월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by