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

149 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 9 de Sept. de 2021
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);
...

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by