How do I resolve the error "The signal at output port 2 of 'ftranssine2freq/MATLAB Function/ SFunction ' is a variable-size signal with a nondiscrete sample time.."
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone I was trying some simple code to find fourier transform of two cosines of different frequency numerically i.e., without using the function fft() as my guide has advised me to calculate it numerically for some specific purpose. after running the codes I am getting following error: The signal at output port 2 of 'ftranssine2freq/MATLAB Function/ SFunction ' is a variable-size signal with a nondiscrete sample time.
function y = fcn(z)
%#codegen
y=z;
N=250;
ts=.002;
u=[0:N-1]*ts;
k=0;
for f=0:1:800
k=k+1;
y(k)=real(trapz(u,z.*exp(-1i*2*pi*f*u)));
end
plot(f, abs(y))
0 Kommentare
Antworten (1)
Abhinav Aravindan
am 2 Jan. 2025
Bearbeitet: Abhinav Aravindan
am 2 Jan. 2025
The error you are facing is likely because the “MATLAB Function” block sample time has been set to the default value of “-1”. You may try setting the sample time as per your requirement to resolve the error.
Also, it appears that you are trying to dynamically change the size of “y” in the loop. The variable “k” in the loop is used to index “y”, but if "k" exceeds the initial length of “y”, you may encounter an indexing error. Hence, it is recommended to preallocate “y” to the required size.
Please refer to the below link wherein a similar query has been addressed:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!