【问题标题】:xlsread [num] discarding NaNxlsread [num] 丢弃 NaN
【发布时间】:2017-06-02 17:27:16
【问题描述】:

我正在尝试编写一个脚本来从 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有一些初步了解。

【问题讨论】:

    标签: excel matlab nan xlsread


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 2019-02-18
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多