Why can't I import multiple files?
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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
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
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 Center 및 File Exchange에서 Speech Recognition에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!