Both alternative appears a bit problematic
Make an experiment. There is a button [Run and Time].
There must be a third way. Give us a little more background.
.
Step 1. Data structure. What output do you want from your program? That is important to know to choose an appropriate data structure. Maybe, I'm guessing, a "nested" Matlab struct array. "ON" is represented by true and OFF by false. These lines initiate such a struct
clear('day','room')
day = struct( 'slot', false( 1, 12 ) );
room( 1, 120 ) = struct( 'day', repmat( day, [1,7] ) );
Now each one of the "10,080" slots can be accessed in a logical way, e.g.
>> room(45).day(5).slot(9)=true
room =
1x120 struct array with fields:
day
>> room(45).day(5).slot(9)
ans =
1
A logical array might be a better alternative. What is the input (ON/OFF from the rooms) to the system and what kind of output is required? "Having 3000 lines of if statements [...]" is that an m-file or some kind of output from a building automation system?
.
A timing experiment:
Evaluating the button-color for
- 8 buildings
- 4 floors
- 30 rooms
takes less than 0.04 seconds with my five years old vanilla desktop.
.
All the slot information is stored in a structure array:
Building(8).Floor(4).Room(30).TimeSlot
The field TimeSlot holds all time slot data for one week. (I have not included the check-boxes - yet.)
Initiate one time_slot_array with some simple data
vec = datevec( '2014-03-03 00:00:00' );
time_slot_array = nan( 12, 2, 7 );
ssn = @(sdn) round(24*3600*sdn);
iso_week_day = @(sdn) 1 + rem( weekday( sdn - 2 ), 7 );
for iwd = 1 :7
for ts = 1 : 12
time_slot_array(ts,1,iwd) = ssn(datenum( vec + [0,0,iwd-1,7+ts, 0, 0] ));
time_slot_array(ts,2,iwd) = ssn(datenum( vec + [0,0,iwd-1,7+ts,59,59] ));
end
end
Assign the same time_slot_array to all rooms
Building(8).Floor(4).Room(30).TimeSlot = time_slot_array;
is_red = false( 4, 4, 30 );
for bb = 1 : 8
for ff = 1 : 4
for rr = 1 : 30
Building(bb).Floor(ff).Room(rr).TimeSlot = time_slot_array;
end
end
end
Evaluate red/green for all rooms (all will get the color)
cur_sdn = datenum( '2014-03-05 10:52:00' );
cur_ssn = ssn( cur_sdn );
tic
for bb = 1 : 8
for ff = 1 : 4
for rr = 1 : 30
iwd = iso_week_day( cur_sdn );
is1 = cur_ssn >= Building(bb).Floor(ff).Room(rr).TimeSlot(:,1,iwd);
is2 = cur_ssn <= Building(bb).Floor(ff).Room(rr).TimeSlot(:,2,iwd);
is_red( bb, ff, rr ) = any( is1 & is2 );
end
end
end
toc
outputs
Elapsed time is 0.032368 seconds.