필터 지우기
필터 지우기

store data from for cycle

조회 수: 4 (최근 30일)
newuser
newuser 2016년 3월 28일
답변: newuser 2016년 3월 29일
I need to store the data in an array. I have a plot Y versus the time (tfinal =m) and the Y value is calculated n-times from a n-loop. I need to store the data in mxn array. at the moment I am able to store just 1xn vector, loosing the information on the time. The part of the m.file are the following
index=0
for i=1:Loop
t=0; %start time
t_end=40; %end time
t_sample=1; %sample interval for gathering data
........
j=1;
t_ar(1,t_end/t_sample+1)=0;
t_ar(1,j)=t;
Y1_ar(1,t_end/t_sample+1)=0;
Y1_ar(1,j)=Y1;
etc etc
end

채택된 답변

MHN
MHN 2016년 3월 28일
you should simply use two for:
m =5; n=7;
Mat = zeros(m,n);
for i = 1:m
for j = 1:n
Mat(i,j) = i+j;% what ever
end
end

추가 답변 (1개)

newuser
newuser 2016년 3월 29일
Hi I have use this m =Loop; n=t_end; Mat = zeros(m,n); for i = 1:m for j = 1:n Y4_array(i,j) = i+j;% what ever end end
at the end of the n-loop and if I try to visualize Y4_array(i,j) I can see Y4_array(i,j)
ans =
30

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by