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

3 次查看(过去 30 天)
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 个评论
ARGY B
ARGY B 2019-6-6
编辑:dpb 2019-6-6
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 2019-6-6
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by