Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
ARGY B
ARGY B am 6 Jun. 2019
Bearbeitet: dpb am 6 Jun. 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 Kommentare
ARGY B
ARGY B am 6 Jun. 2019
Bearbeitet: dpb am 6 Jun. 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 am 6 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by