Why am I not getting an array of values?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Justin Goh
am 9 Mär. 2022
Kommentiert: Justin Goh
am 10 Mär. 2022
I am trying to plot a sinc function and eventually use it for a convolution. The sinc function is defined as h = sin(n*pi/2)/(n*pi/2), where n = -7:7.
When I run my code as is, ith becomes a single value instead of an array. However I noticed that if I define my function as h = sin(n*pi/2), h becomes an array of 1x15, which is what I want. Can somebody explain why this happens and how to go about this.
Thank you in advance.
n = -7:7; % an array of 1x15
p = (pi*n/2);
h = sin(pi*n/2)/(pi*n/2); % this becomes a single value
h1 = sin(p)/p; % this becomes an array of 1x15
0 Kommentare
Akzeptierte Antwort
Voss
am 9 Mär. 2022
Use element-wise division, ./
n = -7:7; % an array of 1x15
p = (pi*n/2);
h = sin(pi*n/2)./(pi*n/2) % this becomes an array of 1x15
h1 = sin(p)./p % this becomes an array of 1x15
isequaln(h,h1)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!