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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by