Problem with overwriting values in vector

3 views (last 30 days)
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 Comments
madhan ravi
madhan ravi on 9 Feb 2019
What’s your desired output from the above code ? State it explicitly.
Paulina Urban
Paulina Urban on 9 Feb 2019
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 :(

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!