Merging 10 scatter plots produced with different RNG sequences
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (3)
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.
0 Comments
Om
on 4 Apr 2016
1 Comment
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
Om
on 5 Apr 2016
Edited: Om
on 5 Apr 2016
2 Comments
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
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.
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!