How to loop over a function call?

3 ビュー (過去 30 日間)
Avish Naredi
Avish Naredi 2021 年 9 月 20 日
コメント済み: Avish Naredi 2021 年 9 月 21 日
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
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.
Avish Naredi
Avish Naredi 2021 年 9 月 20 日
編集済み: Avish Naredi 2021 年 9 月 20 日
Hey, I have edited my question. I hope it is clear now. This function would be optimized on x, over different y values. So, by somehow I want to loop the calculations

サインインしてコメントする。

採用された回答

Walter Roberson
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
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 (:).'
Avish Naredi
Avish Naredi 2021 年 9 月 21 日
Yes, Thanks a lot. This is working

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by