Why can't I import multiple files?

1 次查看(过去 30 天)
George Scott
George Scott 2018-3-27
评论: Jan 2018-3-28
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.

回答(1 个)

Guillaume
Guillaume 2018-3-27
编辑:Guillaume 2018-3-28
'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 个评论
Guillaume
Guillaume 2018-3-28
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 2018-3-28
@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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Speech Recognition 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by