Storing Variables in a loop to out put in a table
    4 ビュー (過去 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 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Tables についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



