0

我正在尝试编写一个脚本来从 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

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

在excel中可能有更好的方法,但我不熟悉它,我只是对Matlab有一些初步了解。

4

1 回答 1

0

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

于 2017-06-02T00:26:21.610 回答