2 values for inputs of a function
이전 댓글 표시
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?
답변 (1개)
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
Jane Smith
2020년 11월 17일
Stephan
2020년 11월 17일
Maybe working with the sum:
B = 5;
C = [25; 60];
D = 0;
k = 1;
am =1;
[T,L] = answ(k,am,D,C,B)
function [T,L] = answ(k,am,D,C,B)
L = sum(book(B) + cart(C) + desk(D));
T= 2*L + am*4 + k*3;
end
function b=book(B)
b=sum(B*4.2);
end
function c=cart(C)
c=sum(2*C.^2);
end
function d=desk(D)
d=sum(D*1.30);
end
Jane Smith
2020년 11월 17일
Jane Smith
2020년 11월 17일
Stephan
2020년 11월 17일
Comment out old code or use my in a new script. Copy the whole code and run it.
카테고리
도움말 센터 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!