44 views (last 30 days)

Show older comments

I have a similar question as asked back on Jan 21, 2010. But being a rank beginner, I couldn't understand or implement that answer. I have a large dataset of biological samples that I plot out as a graph, one sample at a time. The data are in an array with columns = sample number, and rows = measurements taken over time. I wrote a simple script to plot each sample and move forward through the dataset one sample at a time merely by hitting any key. For instance, here is my script for 10 samples measured 600 times (10 columns, 600 rows):

for k = 1:10

trace = (data(:,k));

plot(trace)

hold on;

title(['cell # ',num2str(k),'']);

hold off;

waitforbuttonpress

end

Is there a simple way to alter this script so that I can scroll backward as well as forward?

Thanks!

Walter Roberson
on 24 Sep 2016

Edited: Walter Roberson
on 24 Sep 2016

fig = gcf;

ax = axes('Parent', fig);

max_k = 10;

k = 1;

while k <= max_k

trace = (data(:,k));

plot(ax, trace)

hold(ax, 'on');

title(ax, ['cell # ',num2str(k),'']);

hold(ax, 'off');

was_a_key = waitforbuttonpress;

if was_a_key && strcmp(get(fig, 'CurrentKey'), 'uparrow')

k = k - 1;

else

k = k + 1;

end

end

Walter Roberson
on 25 Sep 2016

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

Start Hunting!