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!

 采纳的回答

Sean de Wolski
Sean de Wolski 2012-5-25

0 个投票

A+N

1 个评论

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!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by