How to loop over a function call?
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to evaluate a function Least_square(), over multiple iterations and return its sum. I am currently doing this by
fun = @(x) ( Least_square(x,y1) + Least_square(x,y2) + Least_square(x,y3) + Least_square(x,y4) )
Is there a better method to do this? Since I may want to evaluate it over multiple iterations
Thanks
댓글 수: 2
David Hill
2021년 9월 20일
Do not understand what you want. What are x.Nd and x.mD1? It does not look like you are changing the inputs to your function.
채택된 답변
Walter Roberson
2021년 9월 20일
편집: Walter Roberson
2021년 9월 20일
y = [y1, y2, y3, y4]
fun = @(x) reshape(sum(arrayfun(@(Y) Least_square(x(:), Y), reshape(y, 1, [])),2), size(x))
댓글 수: 5
Walter Roberson
2021년 9월 20일
In the case that you know that Tvalues and so on are row vectors, then you can leave out the (:).'
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!