Why it is not possible to do array indexing directly after function that returns array?
Ältere Kommentare anzeigen
Maybe it is a stupid question but I don't understand why it is not possible to do array indexing directly after function in my case fft(signal).
My code looks like this:
fs = 48000;
N = fs;
n = 0 : N-1;
sin440 = sin((2*pi/N)*440*n);
Y = fft(sin440);
frequencySpectrum = abs(Y(1:fs/2));
This works just fine but why is not possible in Matlab to replace last two rows with just one; like this:
frequencySpectrum1 = abs(fft(sin440)(1:fs/2))
This row gives this error:
1 Kommentar
per isakson
am 3 Apr. 2021
That's a design decision.
Akzeptierte Antwort
Weitere Antworten (2)
Bruno Luong
am 3 Apr. 2021
Bearbeitet: Bruno Luong
am 3 Apr. 2021
There might be some syntax confusion that leads TMW not to do that. The issue is that the indexing and function argument both use parenthesis "(" ")".
For the moment
z = peaks
return arrays 49 x 49
z = peak(10)
returns now output 10 x 10. That is OK.
But let us suppose the proposed casecade indexing parenthesis, then given the expression
z = peaks(10)
should the parser decides that is equivalent to
z = peak
z = z(10)
or just 10 is the argument of peak ?
JK
am 5 Apr. 2021
0 Stimmen
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!