使用工程符号将数据导入Matlab

时间:2015-07-24 08:22:24

标签: matlab nan notation xlsread

我有一个.xls文件,我想通过xlsread函数将它导入Matlab ..我得到带有工程符号的数字的NaN ..就像我得到15.252 B或1.25 M的NaNs 有什么建议吗?

更新:我可以使用[num,txt,raw] = xlsread('...'),原始的正是我想要的但是如何用(* 10 6 )替换Ms?

2 个答案:

答案 0 :(得分:0)

编辑:

  

Matlab不提供任何工程格式的字符串内置格式。

来源:http://se.mathworks.com/matlabcentral/answers/892-engineering-notation-printed-into-files

在源代码中,您还会找到对您有帮助的功能。

答案 1 :(得分:0)

首先,您可以使用

从单元格数组中的excel中提取所有内容
[~,~,raw] = xlsread('MyExcelFilename.xlsx')

然后你可以编写一个简单的函数,它根据'B','M'等从字符串中返回一个数字。这是一个例子:

function mynumber = myfunc( mystring )
% get the numeric part 
my_cell = regexp(mystring,'[0-9.]+','match');
mynumber = str2double(my_cell{1});
% get ending characters
my_cell = regexp(mystring,'[A-z]+','match');
mychars = my_cell{1};
% multiply the number based on char
switch mychars
    case 'B'
        mynumber = mynumber*1e9;
    case 'M'
        mynumber = mynumber*1e6;
    otherwise
end

end

当然还有其他方法可以将数字字符串与其余字符串分开,使用您想要的方法。有关详细信息,请参阅regexp文档。最后使用cellfun将单元格数组转换为数字数组:

my_array = cellfun(@myfunc,raw);