Error importing excel table into app designer table

Hi,
I am a beginner to MATLAB and making an application using App Designer. I have been working and haven't been able to find an answer online, but I am trying to get a button in my app so that; when the button is clicked, I can choose a excel(csv) file to display onto the UI table once chosen.
However, I am receiving the following error; Error setting property 'Data' of class 'Table': Values within a cell array must be numeric, logical, or char
Is there a problem with my code or is this an issue with my data set? My data set contains a mixture of integers, strings, date and time.
Below is my code for the callback on the button;
[filename, pathname] = uigetfile({'*.csv'},'File Selector');
fullpath = strcat(pathname,filename);
x = readtable(fullpath);
app.UITable.Data = table2cell(x);
Many Thanks for your help

4 件のコメント

Kojiro Saito
Kojiro Saito 2018 年 10 月 2 日
I couldn't reproduce this with my CSV data. Could you provide your sample (extracted) CSV?
Tamim Hussain
Tamim Hussain 2018 年 10 月 2 日
Hi, I think it’s because my csv data has date and times in a few columns and cell arrays do not support that data type. Would there be a way around this so that I’m able to import date/time fields?
Kojiro Saito
Kojiro Saito 2018 年 10 月 3 日
Is it possible to provide your sample data? Because I've created a dummy csv file as the attached and it works without an error with your above codes. I think it's difficult to investigate why the error occurs without your sample data.
Tamim Hussain
Tamim Hussain 2018 年 10 月 3 日
編集済み: Tamim Hussain 2018 年 10 月 3 日
Hi, I have attached the data I am using, you will see there is a field called date posted and time posted (date and time data type in the csv file). Also I tried importing your sample data in App Designer and I still get the same error.

サインインしてコメントする。

 採用された回答

Kojiro Saito
Kojiro Saito 2018 年 10 月 5 日

3 投票

In case of your Journals.csv, you don't need to use table2cell. Just setting a table as a value works.
x = readtable(fullpath);
app.UITable.Data = x;
% Change column name from imported data
app.UITable.ColumnName = x.Properties.VariableNames;
Result in App Designer.

4 件のコメント

Tamim Hussain
Tamim Hussain 2018 年 10 月 7 日
This worked! Thank you so much, really appreciate your help!
Micaela Boursier
Micaela Boursier 2019 年 8 月 6 日
Is there a way to pull a specific cell value into app designer,
for example, a user inputs the number that appears in the first column, and based on that value the remaining values in that row would be directed to designated text value boxes in app designer? This way specific values could be changed, for faster editing.
KRISHNA PATIL
KRISHNA PATIL 2021 年 10 月 13 日
Thank you Kojiro Saito today you made my day as I was looking for someting and got the exact what i want. can you please help me for standaloon application further more. waiting for your reply.
Kojiro Saito
Kojiro Saito 2021 年 10 月 14 日
Could you post your question in MATLAB Answers?

サインインしてコメントする。

その他の回答 (1 件)

sarthak rawat
sarthak rawat 2018 年 12 月 21 日

0 投票

error:"Struct contents reference from a non-struct array object."
comes in line "app.UITable.ColumnName = x.Properties.VariableNames"
please help!!

2 件のコメント

Kojiro Saito
Kojiro Saito 2018 年 12 月 25 日
Could you give more detail information (codes or mlapp and csv data) to investigate why the error occurs, please?
Rubén García García
Rubén García García 2020 年 4 月 18 日
function seleccionararchivoButtonPushed(app, event)
global archivo
[ filname, pathname ] = uigetfile({'*.xlsx'},'File Selector');
fullpathname = strcat(pathname,filname);
archivo = xlsread(fullpathname);
app.Label.Text = filname;
app.UITable.ColumnName = [{'Gb','Ta','Ta','Ts','Flujo'}];
app.UITable.Data = array2table(archivo);

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by