To assign to or create a variable in a table, the number of rows must match the height of the table.

148 次查看(过去 30 天)
file='Phototransistor.xlsx';
time=(1:60)';
t=table('Size',[60 7],'variableTypes',["double" "double" "string" "double" "string" "double" "string"]);
column_name={'Time','Voltage','Color','BPM','State','Speed'};
f=uifigure('Name','UITable','Position',[700 375 550 425]);
t.Time=time;
t.Voltage=readmatrix(file,'Range','B:B');
t.Color='Red';'Black';'Ground';'Blue';
t.BPM=readmatrix('EKG.xlsx','range','A450:A750');
t.State='Relaxed';'Stressed';
t.Speed=readmatrix('Accelerometer.xlsx','range','B:B');
uit=uitable(f,'Data',t,'Position',[15 10 525 400]);
uit.ColumnWidth={'auto','auto','auto','auto','auto','auto'};
This is my code to create a UITable but I keep getting the same error:
To assign to or create a variable in a table, the number of rows must match the
height of the table.
Can someone help.

回答(1 个)

Sulaymon Eshkabilov
There are some size issues overlooked while assigning the table array. Here are the corrected parts of your code:
...
time=(450:750)'; % Note the size: 'A450:A750'
column_name={'Time','Voltage','Color','BPM','State','Speed', 'Something'}; % Note the how many column names are to be there. It is 7 but not 6 as assigned in your code.
t=table('Size',[numel(time) 7],'variableTypes',["double" "double" "string" "double" "string" "double" "string"], ...
'VariableNames', column_name);
...

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by