Undefined function or variable
Show older comments
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 Comments
Geoff Hayes
on 2 Jan 2019
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
on 2 Jan 2019
Edited: Image Analyst
on 2 Jan 2019
Image Analyst
on 2 Jan 2019
Alexander, not sure you saw my Answer down in the official "Answers" section below. Did you?
Accepted Answer
More Answers (0)
Categories
Find more on Scripts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!