Each data point plots as individual points not as one set of many points
1 view (last 30 days)
Show older comments
Abraham Cisneros
on 24 Nov 2021
Commented: Abraham Cisneros
on 28 Nov 2021
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
0 Comments
Accepted Answer
Kevin Holly
on 24 Nov 2021
Edited: Kevin Holly
on 24 Nov 2021
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
More Answers (1)
Yongjian Feng
on 24 Nov 2021
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)');
See Also
Categories
Find more on National Instruments Frame Grabbers 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!