App Designer: Error using readtable "filename" must be a string scalar or character vector.

9 次查看(过去 30 天)
Hello,
Please help me to resolve this issue I've been struggling with for hours on end.
My goal is to use multiselect to select several files and import them as tables to be manipulated independently via the GUI
app.ListBoxFileNames.Items = fileList
app.ListBoxPlotNames.Items
[file, path] = uigetfile('*.*','MultiSelect','on')
if noFiles == 1 % Code works for 1 file
initTable = readtable(file); % init table I think work with in the GUI
app.ListBoxFileNames.Items = fileList; % this is a cell
app.ListBoxPlotNames.Items = fileList;
else % Issues when using multiselect
for i=1:numel(file)
fileListNew = fileList(:,i)
% Below I try to use a structArray to contain a structure consisting of all the tables I import, as I don't know how else to work with the multiple tables
structArray(i) = table2struct(readtable((fileListNew))) % structArray(i)'s I would also like to work with independently in the GUI as separate tables.
app.ListBoxFileNames.Items{i} = fileList;
app.ListBoxPlotNames.Items{i} = fileList;
end
end
Any meaningful assistance would be appreciated. Thank you.

采纳的回答

Cris LaPierre
Cris LaPierre 2021-1-14
编辑:Cris LaPierre 2021-1-14
I suspect the error is with how you are indexing you file names.
First, what is fileList? Shouldn't you be using the files that were just selected? That's file, which is a cell arry. Try using curly braces to index your cell instead of parentheses.
structArray(i) = table2struct(readtable(file{i}));
  5 个评论
Connor Fitzgerald
Connor Fitzgerald 2021-1-14
Just to confirm - my code was exactly as you said so that was not the reason.
I took your advice on simplifying the problem which worked wonders. It seems structs are not good for what I need, due to my tables having different sizes. I have now come to realise that a deeper issue lies in not resizing my table for the second iteration.
Thank you for you time and assistance.
Cris LaPierre
Cris LaPierre 2021-1-14
You might consider a table of tables (see here). However, if you now have a clearer idea of how to organize your data, take the opportunity to do that.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by