フィルターのクリア

Double to cell conversion difficulties

2 ビュー (過去 30 日間)
Joe
Joe 2012 年 1 月 26 日
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 日
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 日
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');

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by