how to make multiple .m files from same data and then add the result of all in one file?

2 views (last 30 days)
the data required for evaluating different functions is this
no_of_machines=6;
no_of_cells=3;
No_of_Parts = 12;
Make_topart_power=[12; 7; 4; 6; 12; 6];
move_cost=[12;13;12;12;13;12;12;12;13;12;12;12];
demand=[1500,1100,1230,1200,1800,1100,1400,1300,1100,1200,1200,2100];
labor_cost=[1.04; 1.2; 1.44; 1.6];
labor_salary=[13000; 15000; 18000; 20000];
labor_capacity=[11700 11700 11700 11700];
OP1=[10 0 0 10 0 20 15;10 13 0 0 12 0 15];
OP2=[0 10 10 15 0 0 20;11 0 13 0 17 10 0];
OP3=[10 0 0 12 11 0 0;0 11 18 0 0 0 17];
OP4=[10 0 0 0 19 0 14;0 14 0 17 0 10 0];
OP5=[18 13 0 0 0 15 0;10 12 0 0 10 0 11];
OP6=[0 10 0 0 0 10 15;12 11 0 13 0 15 0];
setup_cost=[20; 30; 25; 40; 45; 30];
hold_cost=[4; 3; 5; 3; 4; 5];
batch_size=(demand'.*setup_cost.*2./hold_cost).^0.5;
no_of_batches=demand'./batch_size;
M1=[1 0 0 0;0 0 1 0];
M2=[0 0 1 0;0 0 0 1];
M3=[0 1 0 0;0 0 0 1];
M4=[1 0 0 0;0 0 1 0];
M5=[0 1 0 0;0 0 0 1];
M6=[0 0 1 0;0 0 0 1];
M7=[0 1 0 0;0 0 0 1];
ML=[1 0 0;0 0 1;0 1 0;1 0 0;0 1 0;0 0 1;0 1 0];
wl1=[1 0 0 0;0 0 1 0];
wl2=[0 1 0 0;0 0 0 1];
wl3=[0 0 1 0;0 0 0 1];
now I have to use this data to generate different matrices and apply some function for example
E= [OP1;OP2;OP3;OP4;OP5;OP6];
Ez = [size(OP1,1) size(OP2,1) size(OP3,1) size(OP4,1) size(OP5,1) size(OP6,1)];
Ec = [0 cumsum(Ez(1:end-1))];
Ea = allcomb(1:Ez(1),1:Ez(2),1:Ez(3),1:Ez(4),1:Ez(5),1:Ez(6));
En = size(Ea,1);
all_comb_of_OP_routes = cell(1,En);
for i=1:En
all_comb_of_OP_routes{i} =E(Ec+Ea(i,:),:);
end
%% and then apply the function like this
for i=1:numel(all_comb_of_OP_routes)
energy_consumption=(all_comb_of_OP_routes{i}*Make_topart_power).*demand';
total_energy_cost(i)=(sum(energy_consumption))*0.01;
end
how can I save the basic data that is given above in one file and then call the required data in another file for example the 2nd part of code requires OP matrices and Make_topart_power, demand from the basic data.. and then save the file with function name such that after generating all matrices and functions, I can call them in a separate file to add up all.

Accepted Answer

Image Analyst
Image Analyst on 28 Jan 2017
At the bottom of the first script, just save the workspace in a mat file. Then simply open the mat file with load() in any other function of script that needs the variables.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!