Insert elements into a 4D array

5 次查看(过去 30 天)
Hello,
I have a 4-dimensional buffer called:
frameBuffer = zeros (width, height, numChannels, framesPerSymbol);
in which I want to insert 3-dimensional video frames (width, height, numChannels). The variable framesPerSymbol is the number of frames that will go in the buffer, that is, if framesPerSymbol is 10, my buffer will be 10.
And this is where I run it:
frameBuffer = zeros(width, height, numChannels,framesPerSymbol);
framesInBuffer = 0;
while hasFrame(videoObject)
frame = readFrame(videoObject);
shiftBuffer(frameBuffer,frame); % <--------- THIS IS THE PART
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
if framesInBuffer > framesPerSymbol
framesInBuffer = framesPerSymbol;
bypassEncoding = false;
else
bypassEncoding = true;
end
end
The way I was doing the insert was like this, but I don't get results:
function [] = shiftBuffer (frameBuffer,frame)
N = size(frameBuffer,4); % Buffer size
for i = 1:N
frameBuffer(i) = frame;
end

采纳的回答

Srivardhan Gadila
Srivardhan Gadila 2020-4-12
There are 2 mistakes in the above implementation:
  1. Accessing a frame of frameBuffer as frameBuffer(i) instead of frameBuffer(:,:,:,i)
  2. The function shiftBuffer changes the values of frameBuffer locally in the function and in the main code the frameBuffer isn't changed.
I suggest you to make the following changes.
Change the function shiftBuffer as follows:
function frameBuffer = shiftBuffer(frameBuffer,frame,framesInBuffer)
frameBuffer(:,:,:,,framesInBuffer) = frame;
end
and the following lines in your code
frame = readFrame(videoObject);
shiftBuffer(frameBuffer,frame); % <--------- THIS IS THE PART
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
to
frame = readFrame(videoObject);
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
frameBuffer = shiftBuffer(frameBuffer,frame,framesInBuffer);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by