Storing vectors for different time steps in same variable name

2 vues (au cours des 30 derniers jours)
Sudharsan Srinivasan
Sudharsan Srinivasan le 7 Nov 2017
I have a vector A of size 30 by 1, which changes its value for every time steps (ts). How will I store all the values in a same variable name say 'b' ? After storing I have to plot all its changes in single command. How can I do it ?

Réponse acceptée

KL
KL le 7 Nov 2017
Modifié(e) : KL le 7 Nov 2017
Why don't you use a matrix?
Let's say you have 10 timesteps (1 to 10),
ts = 1:10;
so now you'll need to track A's changes during every timestep. So create a 30x11 matrix and the first column being A's initial values.
A = zeros(30,11);
fill first column with initial values,
A(:,1) = rand(30,1);
now do something which changes this first column during every timestep,
for k=1:numel(ts)
A(:,k+1) = rand*A(:,1); %or even A(:,k+1) = rand*A(:,k);
end
now plot all changes,
plot(A)
you'll see 11 curves each for a timestep plus initial states.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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