assigning argument of function within function
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% 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 comentario
Jan
el 10 de Mayo de 2022
Editada: Jan
el 10 de Mayo de 2022
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.
Respuestas (1)
Davide Masiello
el 10 de Mayo de 2022
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 comentarios
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!