使用GUI matlab读取十进制数

时间:2016-10-11 13:51:29

标签: matlab text-files

我正在使用matlab开发用户界面,它允许浏览和加载文本文件并显示一些曲线。我正面临一个问题,我的文件文本是一组十进制数,matlab正在读取那些数字为两列。 这是一个例子:你在这里找到我正在处理的文件:

enter image description here

运行此代码后:

[filename pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname = strcat(pathname,filename);
text = fileread(fullpathname); %reading information inside a file
set(handles.text6,'string',fullpathname)%showing full path name
set(handles.text7,'string',text)%showing information
loaddata = fullfile(pathname,filename);
xy = load(loaddata,'-ascii','%s');
t = xy(:,1);
i = xy(:,3);
handles.input1 = i;
handles.input2 = t;
axes(handles.axes1);
plot(handles.input1,handles.input2)

曲线看起来如此强烈,所以我使用命令窗口检查了xy = load(loaddata,' -ascii')的结果,这里出现了问题!

enter image description here

所以我现在有12列而不是6列!你可以帮我吗? 我尝试使用strrep(数据,',','。')但它不起作用!

1 个答案:

答案 0 :(得分:0)

由于您使用逗号,对于小数点,您需要先将整个文件作为字符串加载,将,替换为.,然后您可以使用{{1}将整个文件转换为数字数组

str2num