Reputation: 39
As the title suggests I am trying to find the location of NaN numbers in a matrix. At the moment I have a matrix size of <15000x20>. I want to check one coulmn of this and return the locations of values with NaN in them.
This is what I have so far, but it seems ot always return blank.
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
It always returns an empty matrix, not the locations like it should. I know that it has found the values.
Upvotes: 0
Views: 373
Reputation: 5720
find(isnan(data(:,column)))
should do the trick for you.
Here is the full script I used to generate the data
% 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)));
Upvotes: 3