Plot Variables of many .m files in Main.m file

3 Ansichten (letzte 30 Tage)
Zafar Iqbal
Zafar Iqbal am 20 Feb. 2016
Kommentiert: Stephen23 am 6 Mär. 2016
I have Many M files say `GAdeferrableload,GAnondeferrableload,GAinterruptibleload,GAnoninterruptibleload,GAmustrunload,WDO_SG_Code_PL_test1mdeferrableload,WDO_SG_Code_PL_test1mnondeferrableload,WDO_SG_Code_PL_test1minterreuptibleload,WDO_SG_Code_PL_test1mnoninterreuptibleload,WDO_SG_Code_PL_test1mmustrunload,GA_WDO_DeferrableLoad,GA_WDO_NonDeferrableLoad,GA_WDO_InterruptibleLoad,GA_WDONonInterruptibleLoad,GA_WDOMustRunLoad, and one `Mainfile.m file which are all script files and I want to plot variables of all M files in `Mainfile.m` like % Unscheduled and scheduled cost of ga
unscheduledcostga=(sum_unschedule_costdlaga+sum_unschedule_costndlaga+sum_unschedule_costilaga+sum_unschedule_costnilaga)/4;
scheduledcostga=(sum_schedule_costdlaga+sum_schedule_costndlaga+sum_schedule_costilaga+sum_schedule_costnilaga)/4;
% Unscheduled and scheduled cost of wdo
% unscheduledcostwdo=(sum_unscheduledcostdlawdo+sum_unscheduledcostndlawdo+sum_unscheduleilawdo+sum_unschedulenilawdo)/4;
% scheduledcostwdo=(sum_E_Cost_SSdlawdo+sum_E_Cost_SSndlawdo+sum_E_Cost_SSilawdo+sum_E_Cost_SSnilawdo)/4;
% % Unscheduled and scheduled cost of hybrid
% unscheduledcosthybrid=(sum_unscheduledcostdlahybrid+sum_unschedulendlahybrid+sum_unscheduleilahybrid+sum_unschedulenilahybrid)/4;
% scheduledcosthybrid=(sum_E_Cost_SSdlahybrid+sum_E_Cost_SSndlahybrid+sum_E_Cost_SSilahybrid+sum_E_Cost_SSnilahybrid)/4;
figure
grid on
bar(1,unscheduledcostga,.2,'blue') % unscheduled cost by ga
hold on
bar(2,scheduledcostga,.2,'magenta'); % scheduled cost by ga
hold on
% bar(3,unscheduledcostwdo,.2,'green'); % unscheduled cost by wdo
% hold on
% bar(4,scheduledcostwdo,.2,'cyan'); % scheduled cost by wdo
% hold on
% bar(5,unscheduledcosthybrid,.2,'black'); % unscheduled cost by hybrid
% hold on
% bar(6,scheduledcosthybrid,.2,'yellow'); % scheduled cost by hybrid
% hold on
set(gca, 'XTick',1:1:6, 'XTickLabel',{'Unscheduled Cost GA','Scheduled Cost GA','Unscheduled Cost WDO','Scheduled Cost WDO','Unscheduled Cost Hybrid','Scheduled Cost Hybrid'})%'Scheduled with PV', 'Generation Cost',
ylabel('Energy Cost($)')
hold on
When I do it, I got
Undefined function or variable 'sum_unschedule_costdlaga'.
Error in Mainfile (line 123)
unscheduledcostga=(sum_unschedule_costdlaga+sum_unschedule_costndlaga+sum_unschedule_costilaga+sum_unschedule_costnilaga)/4;
Please any suggestion?
the code of mainfile.m are below
---------------------------------------------------------
% clear all
% close all
% clc
tic
addpath('C:\Users\Qazi\Desktop\Journal Paper\Journal Paper one code');
%%Main Program which includes all GA M files,all WDO M files and All Hybrid M files ,the hybrid M files are made by combining GA and WDO
% with the Following Changes/Modificatioms made.
% Genetic Algorithm for 1. Deferrable load 2. Non Deferrable Load 3. Interruptible load 4. Non interruptible load 5. Must run Load or Regular load
GAdeferrableload % 1. Deferrable load appliances Scheduling via GA
save GAdeferrableload.mat
load GAdeferrableload.mat
% disp('Contents of GAdeferrableload.mat:')
% whos('-file','GAdeferrableload.mat')
% whos('-file','GAdeferrableload.mat')
GAnondeferrableload % 2. Non Deferrable load appliances Scheduling via GA
save GAnondeferrableload.mat
load GAnondeferrableload.mat
% disp('Contents of GAnondeferrableload.mat:')
% whos('-file','GAnondeferrableload.mat')
GAinterruptibleload % 3. Interruptible load appliances Scheduling via GA
save GAinterruptibleload.mat
load GAinterruptibleload.mat
% disp('Contents of GAinterruptibleload.mat:')
% whos('-file','GAinterruptibleload.mat')
GAnoninterruptibleload % 4. Non Interruptible load appliances Scheduling via GA
save GAnoninterruptibleload.mat
load GAnoninterruptibleload.mat
% disp('Contents of GAnoninterruptibleload.mat:')
% whos('-file','GAnoninterruptibleload.mat')
GAmustrunload % 5. Must run or Regular load load appliances not Scheduled only its unscheduledload is calculated via WDO
save GAmustrunload.mat
load GAmustrunload.mat
% disp('Contents of GAmustrunload.mat:')
% whos('-file','GAmustrunload.mat')
%%Wind Driven Optimization Algorithm for 1. Deferrable load 2. Non Deferrable Load 3. Interruptible load 4. Non interruptible load 5. Must run Load or Regular load
WDO_SG_Code_PL_test1mdeferrableload % 1. Deferrable load appliances Scheduling via WDO
save WDO_SG_Code_PL_test1mdeferrableload.mat
load WDO_SG_Code_PL_test1mdeferrableload.mat
% disp('Contents of WDO_SG_Code_PL_test1mdeferrableload.mat:')
% whos('-file','WDO_SG_Code_PL_test1mdeferrableload.mat')
WDO_SG_Code_PL_test1mnondeferrableload % 2. Non Deferrable load appliances Scheduling via WDO
save WDO_SG_Code_PL_test1mnondeferrableload.mat
load WDO_SG_Code_PL_test1mnondeferrableload.mat
% disp('Contents of WDO_SG_Code_PL_test1mnondeferrableload.mat:')
% whos('-file','WDO_SG_Code_PL_test1mnondeferrableload.mat')
WDO_SG_Code_PL_test1minterreuptibleload % 3. Interruptible load appliances Scheduling via WDO
save WDO_SG_Code_PL_test1minterreuptibleload.mat
load WDO_SG_Code_PL_test1minterreuptibleload.mat
% disp('Contents of WDO_SG_Code_PL_test1minterreuptibleload.mat:')
% whos('-file','WDO_SG_Code_PL_test1minterreuptibleload.mat')
WDO_SG_Code_PL_test1mnoninterreuptibleload % 4. Non Interruptible load appliances Scheduling via WDO
save WDO_SG_Code_PL_test1mnoninterreuptibleload.mat
load WDO_SG_Code_PL_test1mnoninterreuptibleload.mat
% disp('Contents of WDO_SG_Code_PL_test1mnoninterreuptibleload.mat:')
% whos('-file','WDO_SG_Code_PL_test1mnoninterreuptibleload.mat')
WDO_SG_Code_PL_test1mmustrunload % 5. Must run or Regular load load appliances not Scheduled only its unscheduledload is calculated via WDO
save WDO_SG_Code_PL_test1mmustrunload.mat
load WDO_SG_Code_PL_test1mmustrunload.mat
% disp('Contents of WDO_SG_Code_PL_test1mmustrunload.mat:')
% whos('-file','WDO_SG_Code_PL_test1mmustrunload.mat')
%type ('WDO_SG_Code_PL_test1mmustrunload')
%%Hybrid Algorithm for 1. Deferrable load 2. Non Deferrable Load 3. Interruptible load 4. Non interruptible load 5. Must run Load or Regular load
% GA_WDO_Hybrid_Code_deferrable_load
% GA_WDO_Hybrid_Code_Non_deferrable_load
% GA_WDO_Hybrid_Code_Interruptible_load
% GA_WDO_Hybrid_Code_Non_Interruptible_load
% GA_WDO_Hybrid_Code_MustRun_load
%%GA_WDO Hybrid Code Files
GA_WDO_DeferrableLoad
save GA_WDO_DeferrableLoad.mat
load GA_WDO_DeferrableLoad.mat
% disp('Contents of GA_WDO_DeferrableLoad.mat:')
% whos('-file','GA_WDO_DeferrableLoad.mat')
GA_WDO_NonDeferrableLoad
%whos('-file','GA_WDO_DeferrableLoad.mat')
save GA_WDO_NonDeferrableLoad.mat
load GA_WDO_NonDeferrableLoad.mat
% disp('Contents of GA_WDO_NonDeferrableLoad.mat:')
% whos('-file','GA_WDO_NonDeferrableLoad.mat')
GA_WDO_InterruptibleLoad
save GA_WDO_InterruptibleLoad.mat
load GA_WDO_InterruptibleLoad.mat
% disp('Contents of GA_WDO_InterruptibleLoad.mat:')
% whos('-file','GA_WDO_InterruptibleLoad.mat')
GA_WDONonInterruptibleLoad
save GA_WDONonInterruptibleLoad.mat
load GA_WDONonInterruptibleLoad.mat
% disp('Contents of GA_WDONonInterruptibleLoad.mat:')
% whos('-file','GA_WDONonInterruptibleLoad.mat')
GA_WDOMustRunLoad
save GA_WDOMustRunLoad.mat
load GA_WDOMustRunLoad.mat
% % disp('Contents of GA_WDOMustRunLoad.mat:')
% % whos('-file','GA_WDOMustRunLoad.mat')
%%PV Generation
%PVGeneration
%GeneratorGeneration
%%Variables
%sum_unschedule_costdlaga=0;
%-----------------------------------------------Plots started here----------------------------------------------%
%[uncostdlaga unloaddlaga unpardlaga schcostdlaga schloaddlaga schpardlaga]=GAdeferrableload(sum_unschedule_costdlaga,sum_unscheduledloaddlaga,PAR_unscheduleddlaga,sum_schedule_costdlaga,sum_scheduledloaddlaga,PAR_schedudlaga);
% figure
% grid on
% bar(1,sum_unschedule_costdlaga,.2,'blue') % unscheduled cost by ga
% hold on
% bar(2,sum_unscheduledloaddlaga,.2,'magenta'); % scheduled cost by ga
% hold on
% bar(3,PAR_unscheduleddlaga,.2,'green'); % unscheduled cost by wdo
% hold on
% bar(4,sum_scheduledloaddlaga,.2,'cyan'); % scheduled cost by wdo
% hold on
% bar(5,sum_schedule_costdlaga,.2,'black'); % unscheduled cost by hybrid
% hold on
% bar(6,PAR_scheduleddlaga,.2,'yellow'); % scheduled cost by hybrid
% hold on
% set(gca, 'XTick',1:1:6, 'XTickLabel',{'Unscheduled Cost GA','Scheduled Cost GA','Unscheduled Cost WDO','Scheduled Cost WDO','Unscheduled Cost Hybrid','Scheduled Cost Hybrid'})%'Scheduled with PV', 'Generation Cost',
% ylabel('Energy Cost($)')
% hold on
% Unscheduled and scheduled cost of ga
unscheduledcostga=(sum_unschedule_costdlaga+sum_unschedule_costndlaga+sum_unschedule_costilaga+sum_unschedule_costnilaga)/4;
scheduledcostga=(sum_schedule_costdlaga+sum_schedule_costndlaga+sum_schedule_costilaga+sum_schedule_costnilaga)/4;
% Unscheduled and scheduled cost of wdo
% unscheduledcostwdo=(sum_unscheduledcostdlawdo+sum_unscheduledcostndlawdo+sum_unscheduleilawdo+sum_unschedulenilawdo)/4;
% scheduledcostwdo=(sum_E_Cost_SSdlawdo+sum_E_Cost_SSndlawdo+sum_E_Cost_SSilawdo+sum_E_Cost_SSnilawdo)/4;
% % Unscheduled and scheduled cost of hybrid
% unscheduledcosthybrid=(sum_unscheduledcostdlahybrid+sum_unschedulendlahybrid+sum_unscheduleilahybrid+sum_unschedulenilahybrid)/4;
% scheduledcosthybrid=(sum_E_Cost_SSdlahybrid+sum_E_Cost_SSndlahybrid+sum_E_Cost_SSilahybrid+sum_E_Cost_SSnilahybrid)/4;
figure
grid on
bar(1,unscheduledcostga,.2,'blue') % unscheduled cost by ga
hold on
bar(2,scheduledcostga,.2,'magenta'); % scheduled cost by ga
hold on
% bar(3,unscheduledcostwdo,.2,'green'); % unscheduled cost by wdo
% hold on
% bar(4,scheduledcostwdo,.2,'cyan'); % scheduled cost by wdo
% hold on
% bar(5,unscheduledcosthybrid,.2,'black'); % unscheduled cost by hybrid
% hold on
% bar(6,scheduledcosthybrid,.2,'yellow'); % scheduled cost by hybrid
% hold on
set(gca, 'XTick',1:1:6, 'XTickLabel',{'Unscheduled Cost GA','Scheduled Cost GA','Unscheduled Cost WDO','Scheduled Cost WDO','Unscheduled Cost Hybrid','Scheduled Cost Hybrid'})%'Scheduled with PV', 'Generation Cost',
ylabel('Energy Cost($)')
hold on
please site owner are requested don't delete or hold my question or any of its contents,I want to do it via .mat files because via functions it will be a lengthy process,in above each file at-least 500 variables exist

Akzeptierte Antwort

Stalin Samuel
Stalin Samuel am 20 Feb. 2016
  • You have to create each m file as function Create Functions in Files
  • For Each M file assign a output variable
  • Call all files(i.e. function files ) from a main file
  • Now you can plot all the variables
  2 Kommentare
Zafar Iqbal
Zafar Iqbal am 20 Feb. 2016
these all files i.e i have 20 atleast m files which are script files and contains code which do something if i run each file separately they run ok and gave plots but i want to put all m files name in other m file called main.m which is also a script file and want to make all plots in main.m files and access all variables in plots in main.m from all those m files which are made separately and their names are written in main.m file but i donot want to do it via functions please can you gave example of code how i can do it via functions?
Zafar Iqbal
Zafar Iqbal am 20 Feb. 2016
there are a lot of variables in one m files out of 20 m files refer to your point "For Each M file assign a output variable" how can i access all these all variables in assigned output variable if i make a function for each m file ?i want to access 20 m files in one main.m file and each m file out of 20 contains many variables which are required to be plotted.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by