필터 지우기
필터 지우기

Storing vectors for different time steps in same variable name

조회 수: 2 (최근 30일)
Sudharsan Srinivasan
Sudharsan Srinivasan 2017년 11월 7일
댓글: Sudharsan Srinivasan 2017년 11월 9일
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 ?

채택된 답변

KL
KL 2017년 11월 7일
편집: KL 2017년 11월 7일
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.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by