使用datestr时如何以1乘1的数组显示日期? [英] How can i display date in a 1 by 1 array when i use datestr?
问题描述
我使用datestr
将732154.873773148
传输到26-Jul-2004 20:58:14
,但是当我将其输出到.csv文件时,它将是一个1*20
数组...,但是我想要的是将其存储在1*1
数组,我应该怎么办?
I use datestr
to transfer 732154.873773148
into 26-Jul-2004 20:58:14
, but when i ouput it to a .csv file, it will be an 1*20
array..., but what i want is to store it in a 1*1
array, how should i do?
并且是否存在将26-Jul-2004 20:58:14
转换为2004/07/26 20:58:14
的简便方法?
And does there exist easy method to transfer 26-Jul-2004 20:58:14
to 2004/07/26 20:58:14
?
谢谢:)
data = csvread('4.csv');
date = data(:, 1);
loc = data(:, 2);
record_num = size(loc, 1);
result = zeros(record_num, 2);
new_date = datestr(date);
csvwrite('4_res.txt', new_date);
我想要的是
2004/07/26 20:58:14
但它将是
2,0,0,4,/,0,7,/,2,6, ,2,0,:,5,8,:,1,4
推荐答案
要使日期具有2004/07/26 20:58:14
格式,可以使用:
In order to have the date in the format 2004/07/26 20:58:14
you can use:
new_date = datestr(date,'mm/dd/yy HH:MM:SS');
要编写仅包含1x1单元格的csv文件,您可以使用dlmwrite
,并将空字符串用作分隔符:
To write a csv file with only a 1x1 cell you can use dlmwrite
with the empty string as delimiter :
dlmwrite('4_res.txt',new_date, 'delimiter','')
这篇关于使用datestr时如何以1乘1的数组显示日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!