How to plot Average of several plots( combined using copyobj) ?

53 vues (au cours des 30 derniers jours)
Joana le 19 Août 2018
Commenté : dpb le 19 Août 2018
Hi Everyone, I have data sets of multiple subjects, and i plotted the desired output of each subject in separate plots. Then i wanted to compare them and plot in one figure, so i am using 'Copyobj' for that. It does the job. Now i want to plot the 'Average' of all the subject's output plots. Is it possible to do this when i have combined the separate plots (output of separate programs)?

Réponses (1)

dpb le 19 Août 2018
Not without using the data to compute the average, no...
But using copyobj to combine the plots is the hard way to go about creating the plot...just either
  1. Plot first subject
  2. Add values to running sum
  3. hold on % to add to existing plot
  4. Plot next subject
  5. Add values to running sum
  6. Repeat 4., 5. for rest of subjects
  7. Divide sum by N subjects
  8. Plot mean
Alternatively, read each subject data into array (say S) storing by column for the N subjects, compute
S(:,end+1)=mean(S,2); % put mean in last column
plot(S) % plot, including mean
Above plots against ordinal value; if is an X abscissa, use it as vector or array as well.
  2 commentaires
dpb le 19 Août 2018
The first uses only a single dataset at a time plus the running sum; you don't give any hint of how the data are obtained/organized/etc. so not much to do for writing specific code but
d=dir('appropriatewildcard'); % get subject files
N=length(d); % how many are there
x=importdata(d(1).name); % read first
S=x; % save running sum
plot(x) % plot first
hold on % to add more
for i=2:N % iterate over rest
S=S+x; % accumulate sum
S=S/N; % compute mean
plot(S) % add to plot
Add labels, etc., etc., etc., ... as desired

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by