Error using plot Vectors must be the same length. Error in rain_analysis (line 15) plot(t/T,yt,'-b');

clear all;
close all;
T = 30*24*60*60; % Sampling interval
LT = 360; % Number of sampling
t = (0:LT-1)*T; % Sampling time
%Read data
fid=fopen('caps.dat','rb');
yt=fread(fid,'float32');
fclose(fid);
yt(361) = [];
figure;
plot(t/T,yt,'-b');
grid on;
set(gca,'xlim',[0 max(t/T)]);
xlabel('Time (month)','fontweight','bold');
ylabel('Rainfall (mm)','fontweight','bold');
title('GPCC Rainfall Data in West Java','fontsize',14);
%Fourier transform
F = 1/T; % Maximum sampling frequency
f = F*linspace(0,1,LT); % All sampling frequency
Y = fft(yt)/LT;
Yf = abs(Y);
% All frequency plot
figure;
plot(f,Yf,'-r');
xlabel('Frequency (Hz)','fontweight','bold');
ylabel('Amplitude','fontweight','bold');
title('GPCC Rainfall All Amplitude Spectrum Plot','fontsize',14);
set(gca,'xlim',[0 max(f)]);
grid on;
% True half-frequency plot
NF = F/2; % Nyquist frequency
figure;
plot(f(1:LT/2+1),Yf(1:LT/2+1),'-r');
xlabel('Frequency (Hz)','fontweight','bold');
ylabel('Amplitude','fontweight','bold');
title('GPCC Rainfall One Side Amplitude Spectrum Plot','fontsize',14);
set(gca,'xlim',[0 f(LT/2+1)]);
grid on;

 채택된 답변

yt=fread(fid,'float32');
fclose(fid);
yt(361) = [];
As outside observers, we have no way to know that the file contained exactly 361 single precision values, such that removing the 361 would leave you with exactly 360 values. Perhaps the file had more values.
yt=fread(fid, [1 360], 'float32');
fclose(fid);
would read exactly 360 values (provided they exist in the file.)

댓글 수: 2

F = 1/T; % Maximum sampling frequency
That is incorrect. T is your total time interval (30 days), and the sampling frequency is the number of samples, LT, divided by T (seconds), giving samples per second. The result would be about 0.000139, in particular the value 1/7200 Hz (that is, samples every 2 hours)

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

추가 답변 (0개)

카테고리

질문:

2019년 11월 10일

댓글:

2019년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by