From table generator unit combination of on and off I want to sum the values of the on generator capacity

1 view (last 30 days)
I have 10 genraotor with possiblity of being on (1) or off (0) in a table. whhich give me 1024 states. I am trying to sum the capity of the genrators that are on. the gerators capacity G1-G10 are (500, 800, 1000, 500, 500, 500, 200, 200,200 ,200).
For example lets say at state x we have generator unit combination (1111100000 ) I want to sum the gerator capity (G1+G2+G3+G4+G5) >>>(500 + 800 + 1000 + 500 + 500)

Accepted Answer

Voss
Voss on 24 Apr 2022
You can read the data in that spreadsheet into your MATLAB workspace using readmatrix or another function, and then once you have a matrix of logicals (here I call it G_state), you can do the following:
% generator capacities
G_cap = [500, 800, 1000, 500, 500, 500, 200, 200,200 ,200];
% data from worksheet
G_state = logical([ ...
1 0 0 0 0 0 1 0 0 0; ...
1 0 0 0 0 0 1 0 0 1; ...
1 0 0 0 0 0 1 0 1 0; ...
1 0 0 0 0 0 1 0 1 1]);
% G_cap_all will be a matrix the same size as G_state
% that contains the corresponding G_cap value where
% G_state is true (i.e., 1) and 0 where G_state is
% false (i.e., 0). First, initialize to all zeros:
G_cap_all = zeros(size(G_state));
% replicate G_cap for each row of G_state:
G_cap_replicated = repmat(G_cap,size(G_state,1),1);
% put in the non-zero elements of G_cap_all:
G_cap_all(G_state) = G_cap_replicated(G_state);
% sum along the rows (indices where G_state is false
% are zero in G_cap_all, so they don't contribute):
total_cap = sum(G_cap_all,2);
disp(total_cap);
700 900 900 1100

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!