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

3 vues (au cours des 30 derniers jours)
ad lyn
ad lyn le 28 Oct 2021
Réponse apportée : dpb le 28 Oct 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
  1 commentaire
ad lyn
ad lyn le 28 Oct 2021
thnak you
what's about the 'r' here :fid = fopen('bbg1AR20.sig', 'r')

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 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

Plus de réponses (1)

dpb
dpb le 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.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by