datacursormode and brush help

2 views (last 30 days)
Paul
Paul on 25 Apr 2011
I'm doing an experiment where I repeat the same test and save the results in separate CSV files. I need to time align the results so they overlay correctly. I plot 2 lines on a graph and ask the user to select the two start points. Right now it works if they select a point from the first file first, and the second file next. I would like to make it more dynamic and have it use a selected point on a line and a range of data from the second line. Compare the first Y1 to the range of Y2's and give the X value that corresponds to the closest Y2 value. I also need to know which line the point came from so I can time shift it correctly. Below is how I'm doing it now (don't be too harsh on the code, I'm a newb)
% This section of code is used for the initial plotting algorithms.
Plots.number=inputdlg('How many parameters would you like to plot?');
Plots.number=str2num(Plots.number{1});
for i = 1:Plots.number(1)
a='Please enter parameter ';
prompt=cat(2,a,num2str(i));
Plots.parameter{i}=inputdlg(prompt);
subplot(Plots.number(1),1,i)
plot(Data1.TIME,Data1.(Plots.parameter{i}{1}),Data2.TIME,Data2.(Plots.parameter{i}{1}))
xlabel('Time (seconds)');
ylabel(Plots.parameter{i}{1});
grid on
l=legend(FileName1,FileName2);
set(l,'Interpreter','none');
end
%%Time Aligning Events
fprintf('Please click on the start of the events, blue first then green\n');
[x,y]=ginput(2);
%Now, repeat the plotting with a shift in X equal to the difference between
%the two mouse clicks.
TimeShift=(x(2)-x(1));
for i = 1:Plots.number(1)
subplot(Plots.number(1),1,i)
plot(Data1.TIME,Data1.(Plots.parameter{i}{1}),Data2.TIME-TimeShift,Data2.(Plots.parameter{i}{1}))
xlabel('Time (seconds)');
ylabel(Plots.parameter{i}{1});
axislims=axis;
axis([0 max(Data1.TIME(end),Data2.TIME(end)-TimeShift) axislims(3) axislims(4)]);
grid on
l=legend(FileName1,FileName2);
set(l,'Interpreter','none');
end

Answers (0)

Categories

Find more on Visual Exploration 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!