How to avoid loops

조회 수: 2 (최근 30일)
Bruce
Bruce 2018년 2월 22일
댓글: Star Strider 2018년 2월 22일
I have an array (3xN, day, longitude, temperature), a vector (10 elements long, TestLongitudes), and a longitude tolerance. I'm attempting to, for each day find the longitudes that are with tolerance of any of the TestLongitudes, and return the mean of the temperatures that meet the criteria. I can write a lot of loops to do the comparisons, but I wonder if there's a better way...
Thanks! Bruce

답변 (1개)

Star Strider
Star Strider 2018년 2월 22일
With respect to comparing the longitudes, the ismembertol function comes quickly to mind. You will have to experiment with it and your data to determine if it’s an appropriate option.
You won’t be avoiding loops, just hiding them. Many of these functions have implicit loops within them.
  댓글 수: 2
Bruce
Bruce 2018년 2월 22일
You are, of course, correct about the loops. My assumption is that Mathworks can do it more efficiently than I can :-).
I'll take a look at ismembertol to see if it'll do what I want. Thanks!
Star Strider
Star Strider 2018년 2월 22일
It can. The functions are optimised, and I believe in many functions, compiled.
My pleasure!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by