store the index of nanvalues
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, So i got a matrix, 5 observations for 2 variables
A = 1 2
3 4
3 NaN
Nan 5
Nan 7
I wanna store the position when the value of A is a number. so for variable 1, i got values in row 1,2 and 3. for variable 2, i got values in rows 1 2 4 5
so the result of what I want is:
Answer = 1 1
2 2
3 NaN (because A(3,2) is not a number)
NaN 4
Nan 5
or
Answer 2 = 1 1
2 2
3 4
- 5
0 Kommentare
Antworten (2)
Jos (10584)
am 2 Mär. 2018
Bearbeitet: Jos (10584)
am 2 Mär. 2018
% data
A = [ 1 2
3 4
3 NaN
NaN 5
NaN 7 ]
% engines
tf = ~isnan(A)
Answer1 = nan(size(A))
[Answer1(tf), ~] = find(tf)
Answer2 = arrayfun(@(k) find(A(:,k)), 1:size(A,2), 'un', 0)
2 Kommentare
Jos (10584)
am 2 Mär. 2018
Answer2 is a cell array. Each cell contains a vector with numbers. The first cell corresponds to the first column of A, and holds the rows of that column that are not NaN. Since the amount of non-NanS varies between columns, the lengths of the vectors differ between cells.
Siehe auch
Kategorien
Mehr zu Global or Multiple Starting Point Search finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!