MATLAB Answers

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

조회 수: 3(최근 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
Priyank Goel
Priyank Goel 2021년 8월 23일
Thanks Mathieu and Eric.

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

Community Treasure Hunt

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

Start Hunting!

Translated by