Clear Filters
Clear Filters

what does the "oldx =[x(n);oldx(1:256)]" in the following programm do?

3 views (last 30 days)
fid = fopen('bbg1AR20.sig', 'r');
x = fread(fid,'int16')
oldx = zeros(256,1);
for n = 1: 256000
oldx =[x(n);oldx(1:255)];
end

Accepted Answer

David Hill
David Hill on 28 Oct 2021
for n = 1: 256000
oldx =[x(n);oldx(1:255)];%just reforming the oldx array with x(n) on top and then the next 255 elements of oldx and dropping the last element
end

More Answers (1)

dpb
dpb on 28 Oct 2021
It will (very inefficiently) append the first 255 elements of the (NEW and this is key) oldx vector onto the value of the read-in vector x after the Nth element, replacing the entire oldx vector on every pass through the loop. But, it is reversing x as it prepends it in front of the newly created vector each pass.
Whether this is the intent or not is probably debatable, but the above result is simply written as
oldx=[flipud(x);zeros(255,1)];
One might make presumptions of what was really intended, but that's what it does.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!