Why can't I import multiple files?

3 visualizzazioni (ultimi 30 giorni)
George Scott
George Scott il 27 Mar 2018
Commentato: Jan il 28 Mar 2018
Hi, I'm building a simple speech recognition system. It works by asking for a voice input, and performing the appropriate functions on it. Then, I need it to open all the previously recorded samples, and compare it to them. That part is taken care of (more or less). I cannot seem to import the necessary files. Here is my code, with the error message, if you spot what is causing the problem please share it.

Risposte (1)

Guillaume
Guillaume il 27 Mar 2018
Modificato: Guillaume il 28 Mar 2018
'01.txt' and '1.txt' are two different filename. You ask to load the latter when it's the former that exists.
file = sprintf('%02d.txt', k);
would fix that issue.
However, I am not aware of an importdata that works on a datastore. So your code is going to fail on the next line. You seem to be mixing two completely different things, datastores and importdata. You need to use one or the other.
Finally, rather than hardcoding the count of files and the filenames, which innevitably you'll get wrong as you've just done, why not simply ask matlab what they are?
folder = 'C:/Users/..../...Recognition2'; %can't copy paste from a screenshot, you'll have to type the correct path
files = dir(fullfile(folder, '*.txt')); %get list of text files in the folder. Guaranteed to be correct with no typo!
mydata = cell(1, numel(files));
for fileidx = 1 : numel(files) %number of files guaranteed to be also correct.
mydata{fileidx} = importdata(fullfile(folder, files(fileidx).name));
%...
%Of course, doing mydata{fileidx} = y; after the previous line completely overwrite what has just been loaded
end
  8 Commenti
Guillaume
Guillaume il 28 Mar 2018
As said, it's easier if you copy/paste the error text and code rather than screenshot.
Not sure how that happened but that dir line was nonsense. I've fixed my answer.
Jan
Jan il 28 Mar 2018
@George: Guillaume's suggestion:
files = dir(fullfile(folder, '*.txt'))
Your code:
files = dir(fullfile, '*.txt')
Then the function fullfile does not get any inputs, exactly as the error message tells clearly.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by