Array manipulation with loop

Hello, I have a question about array manipulation:
Having an array A=[1;2;3;4;5;6] What is a simple way to update the array A so that when it loops, array A becomes: A=[2;3;4;5;6;7] for N times!
The element 7 is calculated from the first 6 elements and the values in the column are to be shifted upwards and the new value is to be replaced with the last value of previous array, for N number of times;
All help is very much appreciated, Thank you in advance!

 Risposta accettata

Sean de Wolski
Sean de Wolski il 25 Mag 2012

0 voti

A+N

1 Commento

Behnaz
Behnaz il 25 Mag 2012
Thanks for the quick response Sean, it worked like a charm.
I was also wondering how I could store all the values of A in another array so it is not limited to 6 (the example);
I'm trying to predict the next value of A for a set of data and compare to my original values and find the error!
Time=[0.015;0.03;0.045;0.06;0.075;0.09;0.105];
A=[17;18.5;20.35;22.4;22.68;23.55;24.1];
for i=1:200
T_i=Time + 0.015;
xfit = linspace(0,0.2,50);
coeffs5 = polyfit(Time, A, 5);
new_A=polyval(coeffs5,T_i);
end
Thanks alot!

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by