2 values for inputs of a function

1 visualización (últimos 30 días)
Jane Smith
Jane Smith el 17 de Nov. de 2020
Comentada: Stephan el 17 de Nov. de 2020
If i have a function
example:
function(T,L)=answ(b,c,d)
L= b + c + d
T= 2*L
end
and i have 2 of c which are 25 and 60 1 of b which is 5 and 0 of d
where b c and d have their own equation
How can i input 2 values for c?

Respuestas (1)

Stephan
Stephan el 17 de Nov. de 2020
Editada: Stephan el 17 de Nov. de 2020
In case of a vectorized function (yours is) you can use vector inputs:
b = 5;
c = [25; 60];
d = 0;
[T, L] = answ(b,c,d)
function [T, L] = answ(b,c,d)
L= b + c + d;
T= 2*L;
end
gives vector outputs:
T =
60
130
L =
30
65
  6 comentarios
Jane Smith
Jane Smith el 17 de Nov. de 2020
Error: File: answ.m Line: 8 Column: 27
Function 'answ' has already been declared within this scope.
Stephan
Stephan el 17 de Nov. de 2020
Comment out old code or use my in a new script. Copy the whole code and run it.

Iniciar sesión para comentar.

Categorías

Más información sobre Language Support 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!

Translated by