Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
ARGY B
ARGY B il 6 Giu 2019
Modificato: dpb il 6 Giu 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 il 6 Giu 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by