xlsread [num]丢弃NaN

时间:2017-06-01 23:53:29

标签: excel matlab nan xlsread

我尝试编写脚本来从Excel文件中读取文本列,检查内容,然后将另一列(数字)的单元格内容写入其他Excel文件。

function [ output_args ] = export3( filename,cellranges )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
[~,txt] = xlsread(filename, cellranges);
actRange = strrep(cellranges,'H','D');
[num] = xlsread(filename, actRange);
active = [];
rest = [];
for ii = 1 : length(txt)
    if strcmp(txt{ii},'ACTIVE')
        active(end+1) = num(ii)
    elseif strcmp(txt{ii},'REST-S') 
        rest(end+1) = num(ii);
    end
end
xlswrite('activity.xls',active')
xlswrite('rest.xls',rest')
end

问题在于,如果数字列中存在NaN值,它就会被消除,导致txt单元格和num矢量之间也不匹配,提示“索引”超出矩阵维度。 '错误。我想将NaN值保存在我的数字向量中,我该如何处理?

在excel中可能有更好的方法,但我不熟悉它,我只是对Matlab有一些基本知识。

1 个答案:

答案 0 :(得分:0)

哦,我想通了,这是一个愚蠢的问题,我可以使用raw并将所有内容导出到单元格数组而不是向量中。