Hello,
I have recently started using Matlab and am currently trying to write code to automate the plotting of some data in a 2x2 subplot. I think I have managed to get the code to do that, but I am having problems with the titles of the subplots. Depending on if whole data sets are present or missing, the title of the graphs are mislabelled. When I have all of the data sets present (there are 4 batches of data subdivided in to 8 sets), the titles are correct. If there is a batch missing the titles are mislabelled. I have attached the M file and some example data sets so the problem can be seen first hand. The code for plotting is as follows:
if Batch1Al>0
for k=1:length(Batch1A)
subplot(2,2,1);
legendinfo1A{k}=['B1A - Set ', num2str(Batch1Aleg{k})];
scatter(Time,Batch1.Data(indSet1A{(Batch1A(k))}),'x');
hold on
end
end
if Batch1Bl>0
for k=1:length(Batch1B)
subplot(2,2,1);
legendinfo1B{k}=['B1B - Set ', num2str(Batch1Bleg{k})];
scatter(Time,Batch1.Data(indSet1B{(Batch1B(k))}),'*');
hold on
end
end
legendinfo1=[legendinfo1A legendinfo1B];
legendinfo1=legendinfo1(cellfun(@(x) ~isequal(x,0),legendinfo1));
legend(legendinfo1);
title('Batch 1')
ylabel('Data','FontWeight','bold');
xlabel('Time','FontWeight','bold');
This block of code is repeated four times, once for each batch of data (with the appropriate changes to subplot calls and plot titles). If anyone can see a problem with the code or knows why the title is mislabelled when a batch of data is missing, please let me know.
Thanks.