Hi! Question about mean curve in subplots

1 次查看(过去 30 天)
i have made a subplot (2,1,1) with emg for 5 reflexes in each subplot. Now i would like to make a new figure with subplots (2,1,1) with the average curve for the 5 five reflexes in each subplot.
Script:
clear close all clc files=ls('*.txt');
max_acc=zeros(10,1); index_max_acc=zeros(10,1); max_emg=zeros(10,1); index_max_emg=zeros(10,1); tid=zeros(10,1); differens=zeros(10,1);
for i=1:length(files(:,1)) data = ReadVerTxtData(files(i,:),4); [max_acc(i),index_max_acc(i)] = max(data(:,2)); [max_emg(i),index_max_emg(i)] = max(data(:,3)); differens(i)=index_max_emg(i)-index_max_acc(i); tid(i) = differens(i) * (data(2,1) - data(1,1)); tid(i) = tid(i) * 1000; hold on
if i <= 5
subplot(2,1,1)
plot...
(data( (index_max_acc(i,1) : index_max_acc(i,1)+500), 1) - data( index_max_acc(i,1) ), ...
data((index_max_acc(i,1):index_max_acc(i,1)+500),3))
else
subplot(2,1,2)
plot...
(data( (index_max_acc(i,1) : index_max_acc(i,1)+50), 1) - data( index_max_acc(i,1) ), ...
data((index_max_acc(i,1):index_max_acc(i,1)+50),3))
end
end
subplot(2,1,1)
ylabel('Spænding (mV)')
subplot(2,1,2)
ylabel('Spænding (mV')
xlabel('Tid(s)')
I HAVE TRIED THIS:
figure subplot (2,1,1) meanplot(1) % how do i get the mean of the first plot in my subplot on figure 1?

回答(1 个)

Arnav Mendiratta
Arnav Mendiratta 2017-3-20
The issue is with "meanplot" implementation. Ideally, if you are doing this:
figure, subplot(2,1,1), plot(1:10)
This should open a new figure and plot the graph on the first axes (subplot(2,1,1)). It is not clear from your code what "meanplot" does and what is the first argument ('1') to the meanplot.
One way you can consider to modify your meanplot definition is to pass the handle to the newly created figure and then modifying the 'XData' and 'YData' properties of the axes handles to the figure. This is efficient but complicated approach.
If I have a functioned defined like this:
function meanplot()
plot(1:10)
end
And then I run the following code, I get two different figures with the subplots:
subplot(211), plot(1:10)
subplot(212), plot(5:15)
figure, subplot(211), meanplot

Community Treasure Hunt

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

Start Hunting!

Translated by