MATLAB: How to plot multiple data sets from different files all on the same plot

plot

I'm trying to write a script that does the following: Reads in data from a file _aoi_aware to see which aoi is in use (i.e. which data it needs to plot)
Then prompts the user to open a file based on the determined aoi
Then plots the data in the aoi file, which is in the form of coordinates.
The only problem with this is that the original file that contains which aoi is in use can contain multiple aoi's. I will need all of these plotted. So ultimately, I would like the user to be prompted to load the aoi_aware file, then be prompted to select data from aoi_1, if that is open, and then have the script plot that. But if aoi_2 appears later in the aoi_aware file,then that needs to be plotted as well. So I want the script to check for all aoi's in use and plot all of them on the same plot. Here's the code I have so far, and it keeps looping on aoi_4 and producing errors. I'm not sure how to correct the code I've written to achieve the desired result. All help is appreciated. let me know if I can clarify the question.
[fileName3 pathName3]= uigetfile('~/*_aoi_aware_out_Z.txt','Select the appropriate test file under *_aoi_aware_out_Z.txt');
filepath3=fullfile(pathName3,fileName3);
%%Read columns of data according to format string.
[TimeHdr CameraID_1 CameraID_2 CameraID_3 CameraId_4 CameraID_5 CameraID_6 CameraID_7 CameraID_8 Track_aoi Track_camera] = textread(filepath3, repmat('%s ', 1,11),1);
[Timecell Cam1 Cam2 Cam3 Cam4 Cam5 Cam6 Cam7 Cam8 AOI Cam]=textread(filepath3, '%s %f %f %f %f %f %f %f %f %f %f', 'headerlines', 1);
UTtimeCharArray = char(Timecell);
years = str2num(UTtimeCharArray(:,1:4));
months = str2num(UTtimeCharArray(:,6:7));
days = str2num(UTtimeCharArray(:,9:10));
hours = str2num(UTtimeCharArray(:,12:13));
minutes = str2num(UTtimeCharArray(:,15:16));
seconds = str2num(UTtimeCharArray(:,18:21));
times = datenum(years,months,days,hours,minutes,seconds);
%%Check to see which AOI it's tracking on each min.
for i=1:length(times)
if AOI(i)==1
filepath_aoi1=fullfile(pathname_aoi_1,filename_aoi_1);
[TimeHdr CameraID1 Col1 Row1 Quality1 Width1 RA1 Dec1 Error_est1] = textread(filepath_aoi1, repmat('%s ', 1,9),1);
[Timecell cam1 col1 row1 qual1 wid1 ra1 dec1 error1]=textread(filepath_aoi1, '%s %f %f %f %f %f %f %f %f ', 'headerlines', 1);
%%Plot



figure(1)
plot1=plot(col1, row1, 'c');
grid on
legend(plot1, 'row','column','Location','Best');
datetick('x','HH:MM:SS', 'keeplimits')
title(['TA Gyroscopic Drift' UTtimeCharArray(1,12:19) ' --> ' UTtimeCharArray(end,12:19) ' UT '],'FontSize',10)
%xlim([min(times), max(times)])



xlabel('column');
ylabel('row');
hold on
elseif AOI(i)==2
[filename_aoi_2 pathname_aoi_2]= uigetfile('~/*_AOI_2_out_Z.txt','Select the appropriate test file under **_AOI_2_out_Z.txt');
filepath_aoi2=fullfile(pathname_aoi_2,filename_aoi_2);
[TimeHdr CameraID2 Col2 Row2 Quality2 Width2 RA2 Dec2 Error_est2] = textread(filepath_aoi2, repmat('%s ', 1,9),1);
[Timecell cam2 col2 row2 qual2 wid2 ra2 dec2 error2]=textread(filepath_aoi2, '%s %f %f %f %f %f %f %f %f ', 'headerlines', 1);
%%Plot
figure(1)
plot1=plot(col2, row2,'k');
grid on
%legend(plot1, 'column','row','Location','Best');

datetick('x','HH:MM:SS', 'keeplimits')
title(['TA Gyroscopic Drift' UTtimeCharArray(1,12:19) ' --> ' UTtimeCharArray(end,12:19) ' UT '],'FontSize',10)
%xlim([min(times), max(times)])
xlabel('rows');
ylabel('columns');
hold on
elseif AOI(i)==3
[filename_aoi_3 pathname_aoi_3]= uigetfile('~/*_AOI_3_out_Z.txt','Select the appropriate test file under **_AOI_3_out_Z.txt');
filepath_aoi3=fullfile(pathname_aoi_3,filename_aoi_3);
[TimeHdr CameraID3 Col3 Row3 Quality3 Width3 RA3 Dec3 Error_est3] = textread(filepath_aoi3, repmat('%s ', 1,9),1);
[Timecell cam3 col3 row3 qual3 wid3 ra3 dec3 error3]=textread(filepath_aoi3, '%s %f %f %f %f %f %f %f %f ', 'headerlines', 1);
%%Plot
figure(1)
plot1=plot(col3, row3,'g');
grid on
%legend(plot1, 'column','row','Location','Best');
datetick('x','HH:MM:SS', 'keeplimits')
title(['TA Gyroscopic Drift' UTtimeCharArray(1,12:19) ' --> ' UTtimeCharArray(end,12:19) ' UT '],'FontSize',10)
%xlim([min(times), max(times)])
xlabel('column');
ylabel('row');
hold on
else AOI(i)==4
[filename_aoi_4 pathname_aoi_4]= uigetfile('~/*_AOI_4_out_Z.txt','Select the appropriate test file under *_AOI_4_out_Z.txt');
filepath_aoi4=fullfile(pathname_aoi_4,filename_aoi_4);
[TimeHdr CameraID4 Col4 Row4 Quality4 Width4 RA4 Dec4 Error_est4] = textread(filepath_aoi4, repmat('%s ', 1,9),1);
[Timecell cam4 col4 row4 qual4 wid4 ra4 dec4 error4]=textread(filepath_aoi4, '%s %f %f %f %f %f %f %f %f ', 'headerlines', 1);
%%Plot
figure(1)
plot1=plot(col4, row4, 'b');
grid on
%legend(plot1, 'row vs. col','Location','Best');
datetick('x','HH:MM:SS', 'keeplimits')
title(['TA Gyroscopic Drift' UTtimeCharArray(1,12:19) ' --> ' UTtimeCharArray(end,12:19) ' UT '],'FontSize',10)
%xlim([min(times), max(times)])
xlabel('column');
ylabel('row');
hold on
end
i=i+1;
end

Best Answer

...
for i=1:length(times)
if AOI(i)==1
...
elseif AOI(i)==2
...
elseif AOI(i)==3
...
else AOI(i)==4
...
The problem about continuing on case 4 is there's no 'if' on the 'else' so the AOI(i)==4 is meaningless--I'm somewhat surprised Matlab didn't flag it but didn't look at the code in the editor to see if it did give any warning.
If there are only four possible AOI values 1-4, then fixing that to also be elseif will stop that; if there are additional AOI values possible then unless you want them ignored you need to deal with them somewhere. Can't answer that as there's not info on that provided.
If there's a range of values after 3 that all have identical processing then it's likely the SWITCH construction might make writing the logic simpler than the nested IF