assigning argument of function within function
12 ビュー (過去 30 日間)
古いコメントを表示
% complete function
function f = fix(x)
% x is an array of 10 arguments
% these functions
% function1
% function2
% function3
% function4
% function5
% are already there.
%
% I have assigned an array 'x'; now i want to assign the following functions these arguments but ....
% i am getting an error the way i do is as below.
a=function1(x(1),x(2),x(4))
b =function2(x(2),x(5),x(10))
c = function3 (x(3))
d =function4 (x(10),x(9))
e=function5(x(6),x(7),x(8))
fix=a+b+c+d+e;
end
how can i do it.
1 件のコメント
Jan
2022 年 5 月 10 日
編集済み: Jan
2022 年 5 月 10 日
Which error message do you get? This information is important, so it is a good idea to share it with the readers.
What is "function1" etc.? I cannot guess this detail.
One typo:
fix=a+b+c+d+e;
% ^^^ No, not the name of the function, but "f", the output variable
By the way, "fix" is a built-in function. Shadowing it by a user-defined function can cause severe side-effects.
回答 (1 件)
Davide Masiello
2022 年 5 月 10 日
The error is in the last line of the function fix.
Change that and the code works.
fix(rand(1,10))
% complete function
function f = fix(x)
% x is an array of 10 arguments
% these functions
% function1
% function2
% function3
% function4
% function5
% are already there.
%
% I have assigned an array 'x'; now i want to assign the following functions these arguments but ....
% i am getting an error the way i do is as below.
a=function1(x(1),x(2),x(4));
b =function2(x(2),x(5),x(10));
c = function3 (x(3));
d =function4 (x(10),x(9));
e=function5(x(6),x(7),x(8));
f=a+b+c+d+e;
end
function out = function1(a,b,c)
out = a+b+c;
end
function out = function2(a,b,c)
out = a+b+c;
end
function out = function3(a)
out = a;
end
function out = function4(a,b)
out = a+b;
end
function out = function5(a,b,c)
out = a+b+c;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!