我正在读取一个 plt 文件,但我发现将数据从字符数组转换为数值数组时出现问题。我尝试使用 str2num 和 str2double,结果总是:[] 或 NaN。
[filename pathname] = uigetfile({'*.plt'},'File Selector');
fullpathname = strcat(pathname,filename);
set(handles.text2,'string',fullpathname);%show full path name
loaddata = fullfile(pathname,filename);
fid = fopen(loaddata, 'r');% Read the entire file into memory
contents = fread(fid,'*char')';
fclose(fid);
contents = strrep(contents, ',', '.')% Replace `,` with `.`
data = str2double(contents)% Now convert to numbers`
你在这里找到一些来自内容的样本:
+8.7595000000000000E+03 +0.0000000000000000E+00
+0.0000000000000000E+00 +8.3581639938152974E-01
+0.0000000000000000E+00 +4.6014153848539308E+01
+4.6014153852568526E+01 +0.0000000000000000E+00
+0.0000000000000000E+00 +8.3581639938152974E-01
+0.0000000000000000E+00 +2.2902134241670819E+01`