Question
Hello, I am trying to do a customize buffer but it says that my output has a variable size and I don't wont it. Can someone help me to resolve it ? I put my code below ( u is a vector of 8 double and FFTLength is a size of the buffer) function data = custom_buffer( FFTLength, u) %#codegen persistent buffer next_index % Define initial values if isempty(buffer) buffer = zeros(FFTLength,1); next_index = 1; end % Populate the buffer for k = 1 :8 buffer(next_index) = u(k); end % Increment the location to write to at the next time if next_index < FFTLength next_index = next_index + 9; else next_index = 1; end data = buffer; end
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 25, 2026
function data = custom_buffer( FFTLength, u)
%#codegen
persistent buffer next_index
% Define initial values
if isempty(buffer)
buffer = zeros(FFTLength,1);
next_index = 1;
end
% Populate the buffer
for k = 1 : 8
buffer(next_index) = u(k);
next_index = mod(next_index, FFTLength) + 1;
end
data = buffer;
end
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related variable size Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →