Extracting points within an array

조회 수: 2 (최근 30일)
Patrick Burke
Patrick Burke 2023년 4월 12일
답변: Divyanshu 2023년 4월 17일
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
Dyuman Joshi
Dyuman Joshi 2023년 4월 12일
편집: Dyuman Joshi 2023년 4월 12일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Divyanshu
Divyanshu 2023년 4월 17일
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by