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

조회 수: 118 (최근 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
Sulaymon Eshkabilov 2021년 9월 9일
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