Extracting points within an array

2 visualizaciones (últimos 30 días)
Patrick Burke
Patrick Burke el 12 de Abr. de 2023
Respondida: Divyanshu el 17 de Abr. de 2023
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 comentario
Dyuman Joshi
Dyuman Joshi el 12 de Abr. de 2023
Editada: Dyuman Joshi el 12 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Divyanshu
Divyanshu el 17 de Abr. de 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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by