フィルターのクリア

Merge datetime with another cell for export

3 ビュー (過去 30 日間)
Lindazeta
Lindazeta 2020 年 6 月 25 日
コメント済み: dpb 2020 年 6 月 26 日
How do I combine two matrices of different types? I have a datetime matrix and one with pH values, and I would like to export them in one .csv file from matlab. When I try to merge them I get the error message "All inputs must be datetimes or date/time character vectors or date/time strings."
Is there a way to merge datetime with other cell matrices, and how is it done?

採用された回答

dpb
dpb 2020 年 6 月 25 日
編集済み: dpb 2020 年 6 月 25 日
Sure...
>> c={datetime(now,'ConvertFrom','datenum'),pi}
c =
1×2 cell array
{[25-Jun-2020 08:22:52]} {[3.14]}
>> writecell(c,'C.csv')
>> type C.csv
25-Jun-2020 08:22:52,3.14159265358979
>>
writecell (as well as the various other builtin solutions) has the problem that the date string contains embedded blanks but is not quote-delimited. This means reading the file back in generally takes extra steps to keep the date and time from being broken apart into two variables.
To prevent this, use (what I think should be default instead of not) the 'QuoteStrings' parameter:
>> writecell(c,'C.csv','QuoteStrings',true)
>> type C.csv
"25-Jun-2020 08:22:52",3.14159265358979
>>
  2 件のコメント
Lindazeta
Lindazeta 2020 年 6 月 26 日
Cool, thanks! The only thing though, is that all my dates and values stay on the first row, I need them in 2 columns and 239 rows.. I feel like I'm missing something super obvious...
dpb
dpb 2020 年 6 月 26 日
writecell outputs the cell array to reflect the internal storage order.
Above I created a 1x2 cell array so that is what was written.
Arrange your array as you want/need it to be output.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by