在MATLAB中随时输入数据 [英] importing data with time in MATLAB

查看:162
本文介绍了在MATLAB中随时输入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MATLAB中导入以下文本数据文件:

how can I import the following text data file in MATLAB:

day    time        price       volume
01     8:00:06    29.0000      1000
01     8:00:06    29.1000       200
01     8:02:08    29.0700      1000
01     8:03:12    29.0000      1000

我尝试过以下代码但不起作用:

I tried the following code but doesn't work:

fid = fopen('data.txt');
dateItem = [];
values = [];
while ~feof(fid)
  [dateItem]= [dateItem ; fscanf(fid,'%s %s',2)]; 
  [values]= [values ; fscanf(fid,'%f %f',2)];
end
fclose(fid);


推荐答案

在终端输入help importdata将弹出有关如何使用importdata函数的有用信息。或者,您可以使用主菜单上的导入数据功能(它是MATLAB 2013的一个大按钮,它位于以前版本的菜单栏上),可以生成用于导入特定文件布局的代码。

Typing 'help importdata' at the terminal will bring up useful information on how to use the importdata function. Alternatively, you can use the Import Data feature on your home menu (it's a big button for MATLAB 2013, it's on a menu bar for previous versions) which can generate code for importing your specific file layout.

这篇关于在MATLAB中随时输入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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