I want to fill my table in a loop, the variable names do not change along
조회 수: 1 (최근 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
VBBV
2023년 7월 20일
for u=1:length(change)
Replace the for loop to below
for u=1:length(changen)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!