MATLAB Answers

How to add text and numbers to gui table?

3 views (last 30 days)
Ahmed Roshbik
Ahmed Roshbik on 1 Jul 2021
Answered: VBBV on 2 Jul 2021
i want to get data from excel file with two columns the first one is text data and the second one is numeric data
Pattern VD (mmbbl)
A 4
B 3
C 5
D 6
E 2.6
F 3.6
i tried changing the values to string but the table didn't read them, the code i did
[x,txtData]=xlsread('Pattern Balancing.xlsx','B:B');
y=xlsread('Pattern Balancing.xlsx','C:C');
z=[c y]
where :
x = Pattern
y = VD
Thank you in advance.

Answers (2)

Cris LaPierre
Cris LaPierre on 1 Jul 2021
See these examples on the uitable documentation page. Basically, if you have mixed data types, either use a table or a cell array.
Here's how I might do it
T = readtable("Pattern Balancing.xlsx","VariableNamingRule","preserve")
fig = uifigure;
uit = uitable(fig,'Data',T);

VBBV on 2 Jul 2021
[x,txtData]=xlsread('Pattern Balancing.xlsx','A:A'); % change here
y=xlsread('Pattern Balancing.xlsx','B:B'); % here
z=[c y]
Since the pattern and VD are 1 and 2 cols in excel, you need A:A and B:B ,
otherwise ensure cols in excel where your data is present correspond to scheme used in xlsread function.
BTW, its recommended to use readmatrix or readtable as suggested by @Cris LaPierre

Community Treasure Hunt

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

Start Hunting!