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

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

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 14 de En. de 2021
Editada: Cris LaPierre el 14 de En. de 2021
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 comentarios
Connor Fitzgerald
Connor Fitzgerald el 14 de En. de 2021
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 el 14 de En. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification 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