Storing Variables in a loop to out put in a table
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Mathieu NOE
on 6 Dec 2022
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 Comments
Peter Perkins
on 9 Dec 2022
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 Comments
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!