Extracting points within an array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to find data within an Array, A, that has length less than 120. There are 58 time series saved in A each with different lengths.
for i=1:58
Tg2=SSH_metres(:,A(i));
c=find(~isnan(Tg2));
short(i)=length(c)<120;
end
I have tried this, but this gives an array, short, that is either 1 or 0. Instead, I want the position within A that the value corresponds to. Is there any way of doing this?
1 Kommentar
Dyuman Joshi
am 12 Apr. 2023
Bearbeitet: Dyuman Joshi
am 12 Apr. 2023
Assuming you want the indices for which values of short are 1
out = find(short)
%You can also do this via vectorization
Tg2=SSH_metres(:,A);
c=find(sum(~isnan(Tg2))<120);
If that is not what you want to obtain, please specify more.
Antworten (1)
Divyanshu
am 17 Apr. 2023
As per the description provided, you want to access the indexes of the elements which are not ‘NaN’ from within each of the 58 time series columns of the 2-D array ‘A’. You can have a look at the below demo script and can try understanding it.
A = [1 2 3 4; NaN 2 3 5;NaN NaN 3 6;4 2 4 1];
for i=1:4
col=A(:,i)';
logArray = ~isnan(col);
ind = find(~isnan(col));
length = nnz(logArray);
if length<4
% here you can do the needful operations with 'ind' as it holds the
% list of row numbers for the corresponding column i where the data
% is not 'nan'
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!