Use find function, for more than one value avoiding a for loop

1 vue (au cours des 30 derniers jours)
ARGY B
ARGY B le 6 Juin 2019
Modifié(e) : dpb le 6 Juin 2019
Is there a way to use find function but for more than one value?
Lets say we have a matrix 1000x100 named A, where 100 is the num of simulations and 1000 the serial num of dates. And we want to find the first date, for each simulation, being above a date1.
If date1 is a scalar, then
for j=1:1:size(A,2)
ind(j) = find(A(: , j) > date1,1);
end
the above code works... But what about if date1 has 2 numbers or more.
Is it done only with a for loop? Or there is anoter way?
  3 commentaires
ARGY B
ARGY B le 6 Juin 2019
Modifié(e) : dpb le 6 Juin 2019
What I am looking for can be solved like this :
for j=1:1:size(A,2)
for i = 1:1: length(date1)
ind(j,i) = find(A(:,j) > date1(i),1);
end
end
But I was wondering if there is a way to avoid the second loop
Bob Thompson
Bob Thompson le 6 Juin 2019
I do not know of a way to not use the second loop because you're looking for a set of results based on a series of unique inputs to the find function, and so you need to feed in multiple inputs individually. If you could set something as equal I believe you could use the entire matrix date1 as an input, but I'm not sure how you would translate your inequality to an equivalency. I don't know if I personally have ever tried this, though.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by