Why it is not possible to do array indexing directly after function that returns array?
Afficher commentaires plus anciens
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 commentaire
per isakson
le 3 Avr 2021
That's a design decision.
Réponse acceptée
Plus de réponses (2)
Bruno Luong
le 3 Avr 2021
Modifié(e) : Bruno Luong
le 3 Avr 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
le 5 Avr 2021
0 votes
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!