Storing Variables in a loop to out put in a table
조회 수: 3 (최근 30일)
이전 댓글 표시
The problem I am trying to solve is I need to output 7 variables at 9 different times periods, IE i need a b c ... etc at t1 and then tn = t(n-1) + T/7, but i need each variable saved for each time t2, t3, t4 etc and then output these varibles in a table and 2 of them in a plot, what would be the most efficient way to do this?
댓글 수: 0
답변 (2개)
Mathieu NOE
2022년 12월 6일
hello
try this
clearvars
dt = 0.1;% t increment
iter = 9; % iterations
for ci = 1:iter
time(ci,1) = 1+(ci-1)*dt;
a(ci,1) = (ci-1);
b(ci,1) = (ci.^2);
c(ci,1) = ci+rand(1,1);
d(ci,1) = rand(1,1);
e(ci,1) = rand(1,1);
f(ci,1) = rand(1,1);
end
% figure
plot(time,c,'-*b')
% Create a table from a numeric matrix
X = [time a b c d e f];
T = array2table(X,'VariableNames',{'time' 'a' 'b' 'c' 'd' 'e' 'f'});
댓글 수: 0
Peter Perkins
2022년 12월 9일
Make a timetable:
i = (1:9)';
a = i-1;
b = i.^2;
c = i + rand(9,1);
d = rand(length(i),1);
e = rand(length(i),1);
f = rand(length(i),1);
tt = timetable(a,b,c,d,e,f,RowTimes=seconds(1)+milliseconds(100*(i-1)))
stackedplot(tt)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!