Problem with overwriting values in vector

조회 수: 3 (최근 30일)
Paulina Urban
Paulina Urban 2019년 2월 9일
댓글: Paulina Urban 2019년 2월 9일
Hello,
my problem is with overwritting - i don't know how to overwrite vectors and save only some values. I'm solving ode ( this ode is written by me it is not ode45 or ode23 or other matlab already odefile) where i will have many values and in big netwroks i will have problem with memory - because of this i want to save only some values (for example every 4 value)
Code example of ode:
X(1) = 0.6;
Y(1)= 0.2;
licz = 1;
for tt = 1:0.05:10
l = 1;
X(l+1) = X(l) + ((X(l) *a)+(Y(l)*b));
Y(l+1) = Y(l) + (X(l)*c);
b=1;
if mod(licz,3) == 0
vector1(b) = X(l+1)
vector2(b) = Y(l+1)
end
licz=licz+1;
l=l+1
end
What i want is how to overwrite values in vector for example:
v = zeros(1,2)
step1 v = [1,0]
step2 v = [1,2]
step3 v=[2,3] (value 2 from step 2 is now on first place in vector and on second place is new value)
  댓글 수: 2
madhan ravi
madhan ravi 2019년 2월 9일
What’s your desired output from the above code ? State it explicitly.
Paulina Urban
Paulina Urban 2019년 2월 9일
The desired output from the code should be vector1 and vector2 which will have values calculated by these 2 equations:
X(l+1) = X(l) + ((X(l) *a)+(Y(l)*b));
Y(l+1) = Y(l) + (X(l)*c);
Because I will work on large networks if i will write from each iteration values calculated by this two equations my memory will give an error. Because of this i need to write for example after each iteration which mod(iteration number,3) == 0 and save values solved in this iteration in a vectors.
About this equations, I'm giving first value, second value is calculated, third value is calculated (first value we can delete), fourth value is calculated (second value is calculated). I always need previous value to calcualte next value ( if I'm on iteration i then I need value from previous step i-1 ) - here i think is the problem that I can't find out how to solve it :(

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by