Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
ad lyn
ad lyn am 28 Okt. 2021
Beantwortet: dpb am 28 Okt. 2021
fid = fopen('bbg1AR20.sig', 'r');
x = fread(fid,'int16')
oldx = zeros(256,1);
for n = 1: 256000
oldx =[x(n);oldx(1:255)];
end

Akzeptierte Antwort

David Hill
David Hill am 28 Okt. 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

Weitere Antworten (1)

dpb
dpb am 28 Okt. 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.

Kategorien

Mehr zu Migrate GUIDE Apps 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!

Translated by