Merging 10 scatter plots produced with different RNG sequences

1 view (last 30 days)
Hi all
I have produced 10 scatter graphs which are similar and I wanted to merge the files into a scatter graph with range bars (i.e. Median, Upper Q, Lower Q)
I have the 10 figures saved as .fig and .m/.mat files.
Any tips for doing this please?

Answers (3)

Julian Hapke
Julian Hapke on 4 Apr 2016
you can access the data of each plot by
X=cell(10,1)
Y=X
for ii = 1:10
f = open('figure_ii.fig') % use the correct file names here
X{ii} = get(get(gca,'Children'),'XData')
Y{ii} = get(get(gca,'Children'),'YData')
close(f)
end
to calculate your new data use "quantile"
help quantile
also have a look at
help errorbar
to plot the ranges you calculated.
I hope this helps, otherwise you have to specify your question.

Om
Om on 4 Apr 2016
Basically, the values are saved in 10 files already (.mat)
There are 3 values saved in each file along each point of the x axis.
Matlab doesn't like me loading these individually as it over-writes the data.
I need to create a for loop that loads each file name and plots it on the scatter.
  1 Comment
Julian Hapke
Julian Hapke on 5 Apr 2016
I assume your variable names in each mat-file are the same, so if you just
load('example.mat')
it overrides your current values. So what you could do is just load your data into an array of structures:
data(10).median = []
data(10).lq = []
data(10).uq = []
for ii = 1:10
data(ii) = load('file.mat')
end
to get a vector of each array entry use
[data.median]
and so on

Sign in to comment.


Om
Om on 5 Apr 2016
Edited: Om on 5 Apr 2016
Have managed to load the files now and get the scatter loaded.
Just need to turn it all into error bars now so there isn't 10 lines for each colour only the one line with the median etc.
  2 Comments
Julian Hapke
Julian Hapke on 7 Apr 2016
Edited: Julian Hapke on 7 Apr 2016
I'm not sure what I'm looking at in your plot and you have to be clearer about what is the data you have and what is the plot you want to see. my guess: you want an error bar plot for median, lq and uq, with 10 differing values for median lq and uq at each of 11 x-values. Here you go with some example data, that resembles your plot:
function tst
close all
%
% generate dummy data
data(10).median = [];
data(10).lq = [];
data(10).uq = [];
x = (0:10)';
for ii = 1:10
data(ii).x = (0:10)';
data(ii).median = (linspace(0,0.25,11)+(rand(1,11)*0.02-0.02).*linspace(0,1,11))';
data(ii).uq = (linspace(0,0.35,11)+(rand(1,11)*0.1-0.1).*linspace(0,1,11))';
data(ii).lq = (linspace(0,0.2,11)+(rand(1,11)*0.1-0.1).*linspace(0,1,11))';
end
% plot scatter of everything
figure(1)
hold all
for ii = 1:10
scatter(x,[data(ii).median],'g')
scatter(x,[data(ii).uq],'r')
scatter(x,[data(ii).lq],'b')
end
%
% calculate data for errorbars
errby = mean([data(:).median],2);
errbdwn = mean([data(:).median],2)-min([data(:).median],[],2);
errbup = max([data(:).median],[],2)-mean([data(:).median],2);
% plot errorbars
errorbar(x,errby,errbdwn,errbup,'Color','g');
%
errby = mean([data(:).uq],2);
errbdwn = mean([data(:).uq],2)-min([data(:).uq],[],2);
errbup = max([data(:).uq],[],2)-mean([data(:).uq],2);
errorbar(x,errby,errbdwn,errbup,'Color','r');
%
errby = mean([data(:).lq],2);
errbdwn = mean([data(:).lq],2)-min([data(:).lq],[],2);
errbup = max([data(:).lq],[],2)-mean([data(:).lq],2);
errorbar(x,errby,errbdwn,errbup,'Color','b');
end
Julian Hapke
Julian Hapke on 7 Apr 2016
you mentioned earlier, that each of your 10 mat files contains 3 values, so I don't understand where all the plots in your picture come from, enlighten me.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!