Hello, I simplified my problem with the following example. I want to calculate 4 solutions of my function by using the values in a,b,c row-wise. e.g. the first solution should be with a=1,b=2,c=4, the second a=4,b=4,c=3, the third a=7;b=6;c=2; the fourth a=9,b=3,c=1. I tried several options like arrayfun and rowfun but was always unsuccessful. I am sorry if the title might be misleading... Thanks for any suggestions
a=[1;4;7;9]
b=[2;4;6;3]
c=[4;3;2;1]
x=(1:1:100)'
function= a*x + b*x + c*x;

댓글 수: 1

What is the answer you are looking for exactly?
a*x + b*x + c*x
simplifies to
( a + b + c )*x
which is very easy to do, either with bsxfun or implicit expansion, depending on your Matlab version e.g.
x * ( a + b + c )';
in R2018a

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

 채택된 답변

Ameer Hamza
Ameer Hamza 2018년 6월 14일
편집: Ameer Hamza 2018년 6월 14일

0 개 추천

You didn't mention what went wrong with arrayfun. Here is a working example based on the function you gave
a=[1;4;7;9];
b=[2;4;6;3];
c=[4;3;2;1];
x=(1:1:100)';
result = arrayfun(@(a,b,c) a*x + b*x + c*x, a, b, c, 'UniformOutput', false);
since each time, the function returns an array, therefore 'UniformOutput' need to be set to false. It will return a cell array.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2018년 6월 14일

댓글:

2018년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by