How to get plot in time scale instead of number of image frames?

조회 수: 8 (최근 30일)
Priyank Goel
Priyank Goel 2021년 8월 21일
댓글: Priyank Goel 2021년 8월 23일
Hello,
I am having issue in the plot scale. I have taken 79 frames from a video at an interval of 0.5 seconds. Now when I am plotting the them (shown in the code, subplot(1,3,2)) it is plotting with scale on x axis as number of frames (from 1-79) due to which there is error in frequency plot scale (next plot, subplot(1,3,3)). I want them in the correct time scale of 0.5 sec per frame.
Please suggest the possible solution to get correct time and frequency scale with plot, as I am not frequent to MATLAB.
clear;clf
for i = 1:52;
data(:,:,i) = rgb2gray(imread(sprintf('~/Downloads/4_68_image/scene_%0.4d.bmp',i)));
end
r = 1024;
c = 1024;
data = double(reshape(data,r*c,52));
mode = 1
freq = 1
% % Perform the POD - this is mean subtracted for POD not for DMD
[Phi ,~, C]=svd(data-repmat(mean(data,2),[1 size(data,2)]),'econ');
% Plot the figures
close all
figure('name','POD')
subplot(1,3,1)
imagesc(reshape(Phi(1:r*c,mode),r,c));axis image;set(gca,'Ydir','normal')
subplot(1,3,2)
plot(C(:,mode))
title(sprintf('C_%i',mode))
subplot(1,3,3)
[px, fx]=pwelch(C(:,mode),round(0.9*size(data,2)),round(0.8*size(data,2)),...
2^12,freq);
plot(fx,px);
title(sprintf('P(C_%i)',mode))
set(figure(1),'position',[246 66 370 732])
Thank you for your time and consideration.

답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 8월 23일
hello
as you know the time interval and the number of frames , it's fairly simple to create a time vector in seconds
updated code :
subplot(1,3,2)
frames = size(C,1); % should be 79 in your case
dt = 0.5; % time interval between two frames - in seconds
time = (0:frames-1)*dt;
plot(time,C(:,mode))
  댓글 수: 2
Eric Sofen
Eric Sofen 2021년 8월 23일
And if you make time a duration data type, you'll get some automatic unit labeling on the axis (and then you can do things like changing the format from seconds to minutes or to a timer format like mm:ss if you want and the plot labels will respect that format).
time = seconds((0:frames-1)*dt);
Priyank Goel
Priyank Goel 2021년 8월 23일
Thanks Mathieu and Eric.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by