I like to import a string with multiple pathnames

1 visualización (últimos 30 días)
Erik Verdijk
Erik Verdijk el 26 de Mzo. de 2018
Editada: Stephen23 el 26 de Mzo. de 2018
Hello,
I have a string with multiple substrings. Each of the substrings is a pathname. How can I use importdata or textscan to import these substrings in seperate tables?
  2 comentarios
KSSV
KSSV el 26 de Mzo. de 2018
You have those strings in a text file? Why don't you show the sample of text file?
Erik Verdijk
Erik Verdijk el 26 de Mzo. de 2018
I tried this
[FileName,PathName] = uigetfile('../*.txt','MultiSelect','on','choose','the path');
numfiles = length(FileName); c = char (FileName);
string2=strcat(PathName,c);
for ii = 1:numfiles;
% it work until here
a{ii} = importdata(string2);
end

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 26 de Mzo. de 2018
Try this:
[FileName,PathName] = uigetfile('../*.txt','MultiSelect','on','choose','the path');
numfiles = length(FileName);
a = cell(numfiles,1) ;
for ii = 1:numfiles
c = char (FileName{ii});
string2=strcat(PathName,c);
a{ii} = importdata(string2);
end
  2 comentarios
Stephen23
Stephen23 el 26 de Mzo. de 2018
Do not use strcat for filenames/paths! Always use fullfile.
Also that char does nothing.

Iniciar sesión para comentar.


Stephen23
Stephen23 el 26 de Mzo. de 2018
Editada: Stephen23 el 26 de Mzo. de 2018
uigetfile does not return strings, it returns a cell array of char vectors. Iterating over a cell array is easy, so just do that. Also use fullfile rather than concatenating strings using strcat (or anything else).
[fnm,pnm] = uigetfile('../*.txt','MultiSelect','on','choose','the path');
C = cell(1,numel(fnm));
for k = 1:numel(fnm)
C{K} = importdata(fullfile(pnm,fnm{k}));
end
  2 comentarios
Erik Verdijk
Erik Verdijk el 26 de Mzo. de 2018
Editada: Erik Verdijk el 26 de Mzo. de 2018
Is it possible that I get this as result? I have to say that the file I want to import is rather complicated. It has headerlines and variable names. Sorry if I wasn't clear.
Stephen23
Stephen23 el 26 de Mzo. de 2018
Editada: Stephen23 el 26 de Mzo. de 2018
"Is it possible that I get this as result?"
Of course it is possible. Read the importdata help to know what it returns: the structure and its fieldnames are clearly explained there. Note that you could easily convert the cell array of scalar structures to a more convenient non-scalar structure:
S = [C{:}];
S(1).data
S(1).colheaders
...
S(2).data
...

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by