【问题标题】:Find NaN values in a certain column of a matrix and return the cell location在矩阵的某一列中查找 NaN 值并返回单元格位置
【发布时间】:2014-08-30 14:07:59
【问题描述】:

正如标题所示,我正在尝试在矩阵中查找 NaN 数字的位置。 目前我的矩阵大小为 。我想检查其中的一项并返回其中包含 NaN 的值的位置。

这是我目前所拥有的,但似乎并不总是返回空白。

Input = xlsread('data.xlsx');
TF = isnan(Input); 

prompt = 'Which column to check?  ';
column = input(prompt)

empty = 0;

for i = 1:length(Input)

   empty = find(TF(i, column) == 1)

end

它总是返回一个空矩阵,而不是它应该返回的位置。我知道它已经找到了价值。

【问题讨论】:

    标签: matlab matrix


    【解决方案1】:

    find(isnan(data(:,column))) 应该为您解决问题。

    这是我用来生成数据的完整脚本

    % To create the data. You can read from excel file.
    rows = 100;
    cols = 5;
    data = randi(10000,[rows,cols]);
    for i=1:(rows*cols/25)
        data(randi(rows*cols)) = NaN;
    end
    
    % Take user prompt
    prompt = 'Which column to check?  ';
    column = input(prompt);
    
    % Calculate result
    nans = find(isnan(data(:,column)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      相关资源
      最近更新 更多