Azzera filtri
Azzera filtri

I want to fill my table in a loop, the variable names do not change along

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Image Analyst
Image Analyst il 20 Lug 2023
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.

VBBV
VBBV il 20 Lug 2023
for u=1:length(change)

Replace the for loop to below

for u=1:length(changen)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by