フィルターのクリア

Conversion of arrays to cell array

4 ビュー (過去 30 日間)
Ms. Mat
Ms. Mat 2013 年 1 月 9 日
I have time series data as a pivot in an array.
The first row and first column are headers.
x =
NaN 101 102 103 104
731034 4 3 NaN 3
731035 5 NaN 2 1
731036 6 2 5 2
731037 3 1 4 7
I would like to write the above data into an excel but the first column needs to be dates and not datenum. I tried to create a cell array contaning datestr and other columns and then write it to an excel, but I get an error saying "Element of an array cannot be a character matrix" when data is being written to the excel.
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 9 日
what about nan?

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 9 日
編集済み: Azzi Abdelmalek 2013 年 1 月 9 日
x={'datenum' 'col1' 'col2' 'col3' 'col4'
731034 4 3 NaN 3
731035 5 NaN 2 1
731036 6 2 5 2
731037 3 1 4 7}
x(2:end,1)=cellstr(datestr(cell2mat(x(2:end,1))))
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 9 日
編集済み: Azzi Abdelmalek 2013 年 1 月 9 日
I don't know if you are working with cell or double array
x = [NaN 101 102 103 104
731034 4 3 NaN 3
731035 5 NaN 2 1
731036 6 2 5 2
731037 3 1 4 7]
out=num2cell(x)
idx=find(~isnan(x(:,1)))
out(idx,1)=cellstr(datestr(x(idx,1)))
Ms. Mat
Ms. Mat 2013 年 1 月 9 日
Hi,
I am working with a double array. num2cell and cellstr works fine.
Thank You !
X = [NaN 101 102 103 104;
731034 4 3 NaN 3;
731035 5 NaN 2 1;
731036 6 2 5 2;
731037 3 1 4 7]
XCell = num2cell(X)
XCell(2:end,1) = cellstr(datestr(X(2:end,1)))

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by