Extracting points within an array

4 次查看(过去 30 天)
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 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by