How to get plot in time scale instead of number of image frames?
4 ビュー (過去 30 日間)
古いコメントを表示
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])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/717684/image.jpeg)
Thank you for your time and consideration.
0 件のコメント
回答 (1 件)
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
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);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!