Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Combine reading .txt

조회 수: 1 (최근 30일)
Skydriver
Skydriver 2019년 11월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a coding like this:
% Specify the folder where the files live.
myFolder = 'D:\Home\MultiLinierRegression\OutputCalc';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.txt'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
temp = importdata(fullFileName);
%imshow(imageArray); % Display image.
% drawnow; % Force display to update immediately.
Y=temp(:,1); X=temp(:,2:end);
X=[X temp(:,2:end)];
end
But I don't why my coding only read two files. Actually in my folder I have 18 files.
Thanks
  댓글 수: 7
per isakson
per isakson 2019년 11월 16일
Add the line
reshape( {theFiles.name}, [],1 )
before the for-loop. What does it print to Command Window?
Skydriver
Skydriver 2019년 11월 18일
Finaly I can use my coding by adding [] before looping. It works for me to call several .txt files.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by