Matlab xlsread函数
我有“data.xlsx”文件,其中包含数字和字母的单元格 运行此命令时:Matlab xlsread函数,matlab,xlsx,Matlab,Xlsx,我有“data.xlsx”文件,其中包含数字和字母的单元格 运行此命令时: [num,txt,raw] = xlsread('data.xlsx'); 我得到: num = NaN NaN NaN NaN NaN 6 NaN NaN NaN 4 NaN NaN txt = 'a' 'd' 'g' 'b' 'e' '' 'c' 'f' 'h' '' '' '' 有一种方法可
[num,txt,raw] = xlsread('data.xlsx');
我得到:
num =
NaN NaN NaN
NaN NaN 6
NaN NaN NaN
4 NaN NaN
txt =
'a' 'd' 'g'
'b' 'e' ''
'c' 'f' 'h'
'' '' ''
有一种方法可以得到一个新的变量,它将包含这两个变量?比如:
生的=
也许用num2str
我解决了我的问题,谢谢大家
在yuk的解决方案中,我得到:
p、 我的版本是Matlab 2010a。除了包含带有'NaN'
字符串的单元格(如果这些单元格在输入文件中为空)之外
[~,~,raw] = xlsread('data.xlsx');
%# find numbers
containsNumbers = cellfun(@isnumeric,raw);
%# convert to string
raw(containsNumbers) = cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);
只需在xlsread
之后添加:
containsNaNs = cellfun(@isnan,raw);
raw(containsNaNs) = {''};
您知道您问题中的新_变量与原始变量的内容相同吗?@bdecaf,是的,您是对的,我指的是相同的变量(我更新了主题)。谢谢,但我有一个错误:???在索引1、输出1的统一输出中使用==>cellfun非标量时出错。将“UniformOutput”设置为false。我在回答中使用了我的建议,非常感谢!您是否将这些行放在通话的
xlsread
之后,但在您的行之前?非常适合我。我用错误和我得到的更新了我的主题(谢谢)。
containsNaNs = cellfun(@isnan,raw);
raw(containsNaNs) = {''};