フィルターのクリア

apply arrayfun for a couple of values

5 ビュー (過去 30 日間)
emar
emar 2017 年 7 月 3 日
コメント済み: emar 2017 年 7 月 3 日
Hello,
I wrote a syntax that calculate values of a function in different values. For example
x1=[1 2 10 11];
x2=[10 11 12 14];
C= arrayfun (@(t1,t2) myfunction(A,B,t1,t2),x1,x2,'UniformOutput',0);
% A and B are matrixs
In this example the function will do an operation on A(x1,x2) and B(x1,x2) . The problem is that arrayfun will work on each couple (x1(1),x2(1)), x1(2),x2(2)),etc. But I want it to work on all the values of x1 and x2 (16 couples of values so that it can be applied also to for example (x1(1),x2(3))).
Is there any way to do that without a loop?
Thank you in advance
  2 件のコメント
Stephen23
Stephen23 2017 年 7 月 3 日
x1=[1 2 10 11];
x2=[10 11 12 14];
C= arrayfun (@(x1,x2) myfunction(A,B,t1,t2),x1,x2,'UniformOutput',0);
You define an anonymous function in two variables x1 and x2 but you never use these variables inside the function. The four variables used inside the functions are not defined anywhere. Even more confusingly the two arrays have the same names as the anonymous function's variables. Did you really mean this?:
C = arrayfun (@(t1,t2) myfunction(A,B,t1,t2),x1,x2,'UniformOutput',0);
emar
emar 2017 年 7 月 3 日
Yes, you are right! I edited the mistake

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 7 月 3 日
x1=[1 2 10 11];
x2=[10 11 12 14];
[x,y] = ndgrid(x1,x2)
C = arrayfun (@(t1,t2) myfunction(A,B,t1,t2),x,y,'UniformOutput',0);
  1 件のコメント
emar
emar 2017 年 7 月 3 日
Thank you !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMPC Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by