input freqRange in bandpower doc example returning an error when it is a Mx2 matrix

Hello,
While reading the doc of the function bandpower, I tried the example Percentage of Power in Frequency Bands (Periodogram) (in MATLAB online).
The line
powBands = bandpower(Pxx,F,[50 150;200 300],"psd");
returned the following error:
Error using bandpower
Expected input number 3, FREQRANGE, to be a vector.
Error in bandpower>psdbandpower (line 152)
validateattributes(freqrange,{'numeric'},{'vector','finite','real',...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in bandpower>timedomainbandpower (line 110)
pwr = psdbandpower(Pxx,F,freqrange);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in bandpower (line 65)
pwr = timedomainbandpower(inputArgs{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
which is quite incomprehensible, as the input description stipulate:
Frequency range for the band-power computation, specified as a two-element real-valued vector or as an M-by-2 real-valued matrix. M is the number of intervals along which to compute the band power.
Moreover, there is no mention about that in the Version History section
Did I miss something ?
Best regards,

 Respuesta aceptada

Torsten
Torsten hace alrededor de 23 horas
Editada: Torsten hace alrededor de 23 horas
The specification of "freqRange" as Mx2 matrix was introduced in R2026a. Do you use this MATLAB version already ?
Alternatively, you can use
rng("default")
Fs = 1000;
t = 0:1/Fs:1-0.001;
x = cos(2*pi*100*t) + t.*chirp(t,220,t(end),270) + 0.2*randn(size(t));
[Pxx,F] = periodogram(x,hamming(length(x)),length(x),Fs);
periodogram(x,hamming(length(x)),length(x),Fs)
freqRange = [50 150;200 300];
powBands = [bandpower(Pxx,F,freqRange(1,:),"psd");bandpower(Pxx,F,freqRange(2,:),"psd")];
powTotal = bandpower(Pxx,F,[0 500],"psd");
powPercent = 100*powBands/powTotal
powPercent = 2×1
76.0390 20.6880
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

1 comentario

Hello,
Contrqry to what I said, it's indeed written in the Version History section, thank you for pointing it. I somehow missed the line...
I naively thought that opening an example in MATLAB Online withget the appropriate version version for the code to work... Indeed the matlabRelease function in MATLAB Online return R2025b:
ans =
matlabRelease with properties:
Release: "R2025b"
Stage: "release"
Update: 4
Date: 28-Jan-2026
So I guess that explains it...
Next time I will sleep before posting a question...
Thank you very much !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Abr. de 2026 a las 19:18

Comentada:

hace alrededor de 19 horas

Community Treasure Hunt

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

Start Hunting!

Translated by