MATLAB Answers

Error Message during execution

7 views (last 30 days)
FG
FG on 14 Oct 2020
Commented: FG on 14 Oct 2020
My Code is;
Ave3ON = zeros(size(S));
Ave5ON = zeros(size(S));
Ave7ON = zeros(size(S));
AvethdON = zeros(size(S));
Ave3OFF = zeros(size(S));
Ave5OFF = zeros(size(S));
Ave7OFF = zeros(size(S));
AvethdOFF = zeros(size(S));
for i=1:length(S)
M3=([S(i).HV3]);
M5=([S(i).HV5]);
M7=([S(i).HV7]);
Mthd = ([S(i).thd]);
Ave3ON(i)=mean(M3(90000-S(i).date*1667:90000));
Ave5ON(i)=mean(M5(90000-S(i).date*1667:90000));
Ave7ON(i)=mean(M7(90000-S(i).date*1667:90000));
AvethdON(i)=mean(Mthd(90000-S(i).date*1667:90000));
Ave3OFF(i)=mean(M3(110000:110000+S(i).date*1667));
Ave5OFF(i)=mean(M5(110000:110000+S(i).date*1667));
Ave7OFF(i)=mean(M7(110000:110000+S(i).date*1667));
AvethdOFF(i)=mean(thd(110000:110000+S(i).date*1667));
end
Error Message is;
Error using computeperiodogram>validateinputs (line 196)
The input must be either a vector or two-dimensional matrix.
Error in computeperiodogram (line 61)
[x1,~,y,is2sig,win1] = validateinputs(x,win,nfft);
Error in periodogram (line 215)
[Sxx,w2,RSxx,wc] =
computeperiodogram(x,win,nfft,esttype,Fs,options);
Error in thd>timeTHD (line 126)
[Pxx, F] = periodogram(x,w,n,fs,'psd');
Error in thd (line 89)
[r, harmPow, harmFreq] = timeTHD(plotType, harmType,
varargin{:});
Error in Untitled2 (line 28)
AvethdOFF(i)=mean(thd(110000:110000+S(i).date*1667));
Struct S =
480×1 struct array with fields:
name
date
HV3
HV5
HV7
thd

  1 Comment

FG
FG on 14 Oct 2020
Thank you per isakson

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Oct 2020
Ave3ON(i)=mean(M3(90000-S(i).date*1667:90000));
Ave5ON(i)=mean(M5(90000-S(i).date*1667:90000));
Ave7ON(i)=mean(M7(90000-S(i).date*1667:90000));
AvethdON(i)=mean(Mthd(90000-S(i).date*1667:90000));
Okay, parallel indices into 4 different arrays. Makes sense.
Ave3OFF(i)=mean(M3(110000:110000+S(i).date*1667));
Ave5OFF(i)=mean(M5(110000:110000+S(i).date*1667));
Ave7OFF(i)=mean(M7(110000:110000+S(i).date*1667));
Okay, parallel indices into 3 of the 4 different arrays from above. That's odd, I wonder why the 4th array isn't being used?
AvethdOFF(i)=mean(thd(110000:110000+S(i).date*1667))
The destination location parallels the block of 4 above, and the code structure parallels the three lines above it, but why have you suddenly switched from indexing an array named Mthd, to instead requesting the calculation of Total Harmonic Distortion (thd) ?

  1 Comment

FG
FG on 14 Oct 2020
Thank you Walter.. It wad just a mistyping and it's solved : )

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!