I want to fill my table in a loop, the variable names do not change along
4 次查看(过去 30 天)
显示 更早的评论
Dear,
I want to fill my table in a loop since i do not know how long the table is going to be. The only thing that does not change along is the variable names. Does anyone know how i can fix this? This is my code and i inserted an image of the result i get.
k=1;
if one==1
for p=1:length(change)
Q_table(p,1)=nanmean(Q_plot(p,:));
end
C = cell(1,length(change));
changen = (strcat(string(cell2mat(x(index(1,1),1)))+ ' ',string(cell2mat(x(index(1,1),2))) + ' ', string(cell2mat(x(index(1,1),3)))));
for u=1:length(change)
C{1,k}=convertStringsToChars(changen(1,k));
T(1,k) = table(num2cell(change(1,k)),...
'VariableNames',{convertStringsToChars(changen(1,k)),},...
'RowNames',{'Average flow rate [nL/s]'})
k=k+1;
end
fig = figure('Position',[400 300 900 400]);
% set(cgf,'Name','Average flow rate [nL/s]')
% set(gcf,'Name','Average flow rate [nL/s]','NumberTitle','off') % To keep only your title.
uitable(fig,'Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0.1, 0.2, 6, 0.7]);
titleText = uicontrol(fig, 'Style', 'text', 'String', 'Average flow rate [nL/s]', 'FontSize', 12, 'FontWeight', 'bold', 'Units', 'normalized', 'Position', [0.1, 0.9, 0.8, 0.05]);
end
0 个评论
回答(2 个)
Image Analyst
2023-7-20
I would build your table (fill it with numbers and strings) first, and then after that loop set the variable names for the columns:
T.Properties.VariableNames = {'Var1', 'Measurement2', 'Metric3'}; % or whatever the column names should be.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!