使用datestr时如何以1乘1的数组显示日期? [英] How can i display date in a 1 by 1 array when i use datestr?

查看:73
本文介绍了使用datestr时如何以1乘1的数组显示日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用datestr732154.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆