Processing files using a for loop (2024)

783 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Matt am 21 Feb. 2012

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop

Kommentiert: Walter Roberson am 10 Sep. 2021

Akzeptierte Antwort: Walter Roberson

I am trying to write a program to read in files and analyze each file one by one. The files are wav files, and I want to read them in, filter them with a filter I have already designed, plot frequency vs. time and do a spectrogram of each file. I am supposed to use uigetdir to find the directory of files I want to read into MATLAB, and then analyze each one, hopefully with a 'for loop'. I'm not too advanced, so this may be easy and I'm just missing how to do it. Any help would be appreciated.

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Walter Roberson am 21 Feb. 2012

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#answer_38249

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#answer_38249

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kevin Holst am 21 Feb. 2012

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#answer_38248

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#answer_38248

In MATLAB Online öffnen

something like this:

myDir = uigetdir; %gets directory

myFiles = dir(fullfile(myDir,'*.wav'); %gets all wav files in struct

for k = 1:length(myFiles)

baseFileName = myFiles(k).name;

fullFileName = fullfile(myFolder, baseFileName);

fprintf(1, 'Now reading %s\n', fullFileName);

[wavData, Fs] = wavread(fullFileName);

% all of your actions for filtering and plotting go here

end

9 Kommentare

7 ältere Kommentare anzeigen7 ältere Kommentare ausblenden

Joel Sande am 15 Jan. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_335427

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_335427

You know what ? this code saved my life.

SANKAR JYOTI NATH am 26 Okt. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_401688

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_401688

sir what will be the function if the files are in .txt format?

Walter Roberson am 26 Okt. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_401712

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_401712

In MATLAB Online öffnen

myDir = uigetdir; %gets directory

myFiles = dir(fullfile(myDir,'*.txt'); %gets all txt files in struct

for k = 1:length(myFiles)

baseFileName = myFiles(k).name;

fullFileName = fullfile(myDir, baseFileName);

fprintf(1, 'Now reading %s\n', fullFileName);

num = importdata(fullFileName); %or readtable

% all of your actions for filtering and plotting go here

end

However, .txt files can be complex, and importdata might not be able to handle the format your .txt file is in.

Andrew Smelser am 21 Feb. 2020

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_800413

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_800413

Bearbeitet: Andrew Smelser am 21 Feb. 2020

In MATLAB Online öffnen

This is awesome. A few notes though, There is a typo omitting a closing parenthese and I believe "myFolder" should be replaced with "myDir". I modified the original code you posted to read a bunch of PDF files; it doesn't do anything with them (yet) but for anyone who may get stuck on why it wasn't working here ya go. (R2018b)

Edit 1: Changed some wording in comment to make it more clear

% Just prints to command window the files in a

% directory matching the given extension

%

% Original post:

% https://www.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#answer_38248

myDir = uigetdir;% gets directory

myFiles = dir(fullfile(myDir,'*.m'));% Added closing parenthese!

for k = 1:length(myFiles)

baseFileName = myFiles(k).name;

fullFileName = fullfile(myDir, baseFileName); % Changed myFolder to myDir

fprintf(1, 'Now reading %s\n', fullFileName);

end

Bibek Dhami am 28 Jul. 2020

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_953083

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_953083

In MATLAB Online öffnen

Hi I am using this code to process several files on a folder. I want to get the surf plot out from all the files in the folder. If I process each file individually I am getting it but using this I am getting some error mentioning

Error in surf (line 139)

hh = matlab.graphics.chart.primitive.Surface(allargs{:});

Error in Untitled8 (line 9)

surf(fullFileName,'edgecolor','none');

%%%%%%%%%%%%%%%%%%%%%%

My code is as follows

myDir = uigetdir;% gets directory

myFiles = dir(fullfile(myDir));% Added closing parenthese!

for k = 3:length(myFiles)

baseFileName = myFiles(k).name;

fullFileName = fullfile(myDir, baseFileName); % Changed myFolder to myDir

fprintf(1, 'Now reading %s\n', fullFileName);

surf(fullFileName,'edgecolor','none');

end

But If just use a single file from folder it works

like

A=load('1');

surf(A,'edgecolor','none');

Can anyone guide me on this?

Christian Kunis am 24 Jun. 2021

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1602625

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1602625

In MATLAB Online öffnen

You have to load the data in the loop, not just pass the filename to the surf() function.

For example:

...

fprintf(1, 'Now reading %s\n', fullFileName);

A=load(fullFileName);

surf(A,,'edgecolor','none');

end

(I know this is an old post, I felt like responding anyway. Hopefully it will help someone in the future)

Deepu S S am 10 Sep. 2021

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729069

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729069

In MATLAB Online öffnen

i'm also working on the above shown code. I'm facing some problems .Actually my aim is to read and plot all file ina single axis or subplots. please help me

function CHD_Multiview_Callback(hObject, eventdata, handles)

set(handles.chdprevious, 'Visible','on')

set(handles.chdnext,'visible','on')

set(handles.chdtext,'visible','on')

set(handles.chdpanel,'visible','on')

guidata(hObject, handles);

disp('Entered');

guidata(hObject, handles);

folder_name = uigetdir('','Select src data Directory');

if isequal(folder_name,0)

disp('Directory Selected');

else

% set(handles.EEGFilename,'string','Wait Loading File.......');

disp(['You have selected ', fullfile(folder_name)]);

disp('CHD Audio file processing wait')

handles.srcFolder= fullfile(folder_name);

% set(handles.edDirName,'string',handles.srcFolder);

end

guidata(hObject, handles);

% Specify the folder where the files live.

k='';

myFolder = 'F:\audio';

folder ='F:\';

% AudioArray{k} = audioread(fullfile(folder));

% maxaudio(k) = max(AudioArray{k});

% myFolder = 'F:\audio';

% Check to make sure that folder actually exists. Warn user if it doesn't.

if ~isfolder(myFolder)

errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);

uiwait(warndlg(errorMessage));

myFolder = uigetdir(); % Ask for a new one.

if myFolder == 0

% User clicked Cancel

return;

end

end

% Get a list of all files in the folder with the desired file name pattern.

filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.

theFiles = dir(filePattern);

for k = 1 : length(theFiles)

baseFileName = theFiles(k).name;

fullFileName = fullfile(theFiles(k).folder, baseFileName);

fprintf(1, 'Now reading %s\n', fullFileName);

% fdispf(1,'Now ploting chd %s\n',fullfile);

% Now do whatever you want with this file name,

% such as reading it in as an image array with imread()

AudioArray = audioread(fullFileName);

% [y,fs] = audioread(fullFileName);

% subplot = 'theFiles';

end

In this for loop i want tyo add function to plot all readed audio files .So guys please help me to solve this issue...............

Deepu S S am 10 Sep. 2021

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729074

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729074

Bearbeitet: Walter Roberson am 10 Sep. 2021

In MATLAB Online öffnen

surf(A,,'edgecolor','none');

why using this function i'm very new to MATLAB

Walter Roberson am 10 Sep. 2021

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729089

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/29837-processing-files-using-a-for-loop#comment_1729089

In MATLAB Online öffnen

Compare:

A = sort(randi([-2 9], 300, 500));

surf(A)

title('edgecolor default')

Processing files using a for loop (13)

figure

surf(A, 'edgecolor', 'none')

title('edgecolor none')

Processing files using a for loop (14)

Notice that the first of the two surface plots is nearly completely black, but the second of them, with edgecolor none, looks fine.

The difference is that in the first one, all the edges have been drawn in black. But edges have fixed drawing width: if you draw an edge and then zoom the plot in or out, the edge stays the same thickness on the screen. When you have enough data that the view has to zoom out to look at it all, then the data coordinates get squished together compared to physical drawing coordinates, so the data coordinates at which the edges get drawn get closer together, but the width of the edges stays the same. At some point, the edges are pretty much touching, and all you can see is the edges.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

Signal ProcessingAudio ToolboxMeasurements and Spatial Audio

Mehr zu Measurements and Spatial Audio finden Sie in Help Center und File Exchange

Tags

  • file processing
  • sound waves
  • for loop

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Processing files using a for loop (15)

Processing files using a for loop (16)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Processing files using a for loop (2024)

References

Top Articles
Does Cicis Take Apple Pay
Craigslist Apartments For Rent- Worcester
Cecil Burton Funeral Home | Shelby, North Carolina
Inside Watchland: The Franck Muller Watch Manufacturing Facilities | aBlogtoWatch
Hallmark White Coat Ceremony Cards
General Surgery Spreadsheet 2024
Ticket To Paradise Showtimes Near Laemmle Newhall
Who has the best money market rate right now?
How do you evaluate cash flow?
Lesson 10 Homework 5.3
Schüleraustausch Neuseeland - Schulabschluss mit Study Nelson
Wall Street Journal Currency Exchange Rates Historical
Watch Valimai (2022) Full HD Tamil Movie Online on ZEE5
Jennifer Lenzini Leaving Ktiv
Aly Raisman Nipple
Elisabeth Fuchs, Conductor : Magazine : salzburg.info
Cosmoprof Jobs
New York Rangers Hfboards
V Pay - Alle Informationen zu dem Zahlungssystem für die Girocard
Violent Night Showtimes Near The Riviera Cinema
Dabs Utah State Liquor Store #09 - Murray
Party City Enfield Photos
9xMovies: The Ultimate Destination for Free Movie Downloads
Cocaine Bear Showtimes Near Harkins Cerritos
Drug Stores Open 24Hrs Near Me
Omniplex Cinema Dublin - Rathmines | Cinema Listings
Cardaras Logan Ohio
Obsidian Guard's Skullsplitter
Caliber Near Me
Lux Nails Mcmurray Pa
Tackytwinzzbkup
Police in Germany arrest 25 people allegedly planning to overthrow the government
Clothes Mentor Overland Park Photos
Actionman23
Intriguing Facts About Tom Jones Star Hannah Waddingham
If You Love FX’s 'Shogun,' Here Are 10 More Samurai Things To Check Out
Cashtapp Atm Near Me
National Weather Service Pittsburgh Pa
Myapps Tesla Ultipro Sign In
Bank Of America Financial Center Irvington Photos
Appsanywhere Mst
Alger Grade Ohm
Htmp Hilton
Israel Tripadvisor Forum
Vadoc Gtlvisitme App
Baroque Violin Shop Cincinnati Oh
Trực tiếp bóng đá Hà Nội vs Bình Định VLeague 2024 hôm nay
Pastel Pink Facetime Icon
Skip The Games Mil
Saqify Leaks
Craigslist Free Stuff Bellingham
Jenny Babas Nsfw
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 5720

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.