Undefined function or variable
显示 更早的评论
Hello everyone,
I have written following code to calculate the production costs. The price_matrix is a 360x13 double matrix and the variable a is a binary variable.
The price_matrix is stored in the base workspace. The error "Undefined function or variable 'price_matrix'." occurs. How do I import the matrix in my function.
function [total_costs] = costs_calculation (a)
t=1;
while t<=360
ct=price_matrix(t,2)*a(1,1) +price_matrix(t,3)*a(1,2) + price_matrix(t,4)*a(1,3)+price_matrix(t,5)*a(1,4) +price_matrix(t,6)*a(1,5) + price_matrix(t,7)*a(1,6) +price_matrix(t,8)*a(1,7) +price_matrix(t,9)*a(1,8) + price_matrix(t,10)*a(1,9) +price_matrix(t,11)*a(1,10) +price_matrix(t,12)*a(1,11) + price_matrix(t,13)*a(1,12);
total_costs=total_costs + ct;
end
end
Thanks a lot in advance.
3 个评论
Geoff Hayes
2019-1-2
Alexander - where are you calling the costs_calculation function from? If calling it from the base workspace (command line) then just pass in the price_matrix as an input parameter to this function. If you are not calling this function from the base workspace, then how/where is it being called from (and why is the matrix defined in the base workspace...)?
Alexander Bork
2019-1-2
编辑:Image Analyst
2019-1-2
Image Analyst
2019-1-2
Alexander, not sure you saw my Answer down in the official "Answers" section below. Did you?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Scripts 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!