Each data point plots as individual points not as one set of many points

4 次查看(过去 30 天)
I'm plotting data from a video file, the plot looks as it should, however, I would like to run findpeaks function to locate local maxima throughout the plot. But since each data point is its own individual element, findpeaks or curve fitting does not work. How can I combine all the data points into one set? I attached a screenshot of how the data is currently plotting .
obj = VideoReader('VidName.avi') %same name as file you create in step 1
video = read(obj);
for i=1:150 %number of frames of the video i am analyzing
avrgG(i)=mean2(video(400:420,580:600,2,i)); %color channel im plotting
plot(i,avrgG(i),'ko') %plot the channel you want
title('Green Channel Intensity Plot');
xlabel('Number of Frames');
ylabel('Intensity of Green Channel (counts)');
hold on
pause(.2)
end

采纳的回答

Kevin Holly
Kevin Holly 2021-11-24
编辑:Kevin Holly 2021-11-24
obj = VideoReader('VidName.avi') %same name as file you create in step 1
video = read(obj);
for i=1:150 %number of frames of the video i am analyzing
avrgG(i)=mean2(video(400:420,580:600,2,i)); %color channel im plotting
end
plot(1:150,avrgG,'ko') %plot the channel you want
title('Green Channel Intensity Plot');
xlabel('Number of Frames');
ylabel('Intensity of Green Channel (counts)');
If you still want to see a data point added during for loop:
obj = VideoReader('VidName.avi') %same name as file you create in step 1
video = read(obj);
avrgG(1)=mean2(video(400:420,580:600,2,1)); %color channel im plotting
p = plot(1,avrgG(1),'ko') %plot the channel you want
title('Green Channel Intensity Plot');
xlabel('Number of Frames');
ylabel('Intensity of Green Channel (counts)');
for i=2:150 %number of frames of the video i am analyzing
avrgG(i)=mean2(video(400:420,580:600,2,i)); %color channel im plotting
p.XData = [p.XData i];
p.YData = [p.YData avrgG(i)];
pause(.2)
end

更多回答(1 个)

Yongjian Feng
Yongjian Feng 2021-11-24
plot can take arrays as inputs.
So take the plot call out of the for loop.
obj = VideoReader('VidName.avi') %same name as file you create in step 1
video = read(obj);
for i=1:150 %number of frames of the video i am analyzing
avrgG(i)=mean2(video(400:420,580:600,2,i)); %color channel im plotting
pause(.2) % MIGHT NOT NEED THIS.
end
x = 1:150;
plot(x,avrgG,'ko') %plot the channel you want
title('Green Channel Intensity Plot');
xlabel('Number of Frames');
ylabel('Intensity of Green Channel (counts)');

Community Treasure Hunt

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

Start Hunting!

Translated by