Problem with variable size
Mostrar comentarios más antiguos
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
4 comentarios
Walter Roberson
el 24 de Mzo. de 2021
buffer(next_index) = u(k);
Why are you copying 8 u(k) values to the same buffer(next_index) location ?
Walter Roberson
el 24 de Mzo. de 2021
for k = 1 :8
buffer(next_index) = u(k);
next_index = mod(next_index, FFTLength) + 1;
end
Catteau Ophélie
el 24 de Mzo. de 2021
Walter Roberson
el 24 de Mzo. de 2021
No, that way of coding can expand the array.
Suppose that we have reached next_index = FFTLength - 1. Then buffer(next_index)=u(1) puts u(1) into second last location, increment next_index to FFTLength - 0. u(2) is put there, increment next_index to FFTLength + 1. u(3) is put there... Ooops, we expanded the array!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Execution Speed en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!