MATLAB Answers

iterate through multiple files in a folder

155 ビュー (過去 30 日間)
Nitish Reddy Kotkur
Nitish Reddy Kotkur 2019 年 10 月 19 日
編集済み: Rik 2019 年 10 月 20 日
function [] = lanczos(A, m)
A = readmatrix('output1.txt','Whitespace',' []');
here A reads a single text file.
But i wanted A to read multiples text files(may be using for loop) stored in a folder(say graphs) and the function needs to run through all of them and display output for every text file.
can someone help me with this.
  3 件のコメント
Rik 2019 年 10 月 20 日
The source of the error is that you entered the variable name as a char array instead of the contents of the variable.


回答 (1 件)

Katarina Vuckovic
Katarina Vuckovic 2019 年 10 月 20 日
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir));
M(length(myFiles),s)=zeros; %gets all wav files in struct
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
A = readmatrix(fullFileName,'Whitespace',' []');

Community Treasure Hunt

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

Start Hunting!

Translated by