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

1 view (last 30 days)
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 Comments
ARGY B
ARGY B on 6 Jun 2019
Edited: dpb on 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 on 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.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!