我有一个csv文件有两列,日期和浮点数,日期格式很奇怪(2016年1月1日9:55:00 PM),如何将其导入matlab并将其绘制为情节?这就是我的尝试:
fid = fopen('all.csv');
if fid>0
data = textscan(fid,'%s %d','Delimiter',',');
% close the file
fclose(fid);
end
x = data(:,1);
y = data(:,2);
plot(x,y);
但是我得到的错误没有足够的论点
all.csv示例:
Jan 1 2016 9:55:00 PM, 12493829,
Jan 2 2016 7:55:00 AM, 83747283,
Jan 3 2016 2:55:00 PM, 89572948,
Jan 4 2016 8:55:00 AM, 95862744,
错误:
Error using plot
Not enough input arguments.
Error in test (line 10)
plot(x,y);
答案 0 :(得分:2)
由于您在plot
函数中输入了单元格数组,因此出现错误。
x = data{:,1}; %You need { } here, not ()
y = data{:,2};
plot(1:numel(x), y, 'o-');
%Ensuring the xticks are as required and changing the xticklabels to datetime values and
%rotating the labels for better visualisation ('xticklabelrotation' requires >= R2014b)
set(gca,'xtick',1:numel(x),'xticklabel',x,'xticklabelrotation',45);
输出:
答案 1 :(得分:0)
--oneline