필터 지우기
필터 지우기

Finding area of a plot/graph in a for loop and save answer into array

조회 수: 1 (최근 30일)
Hello Community,
I have a few audio files.
When I open one of these files, I have a file named 'data' in my workspace which contains the data set to plot it's graph.
I am trying to get the area of every audio file in a loop, and save it in an array in a column.
Is anyone able to help with my code especially on : [data,fs] = audioread(Extracted_files(k).name);
I am running into errors for this particular line.
note that every graph is different..
A = zeros(210,1); %set array for allocating the area of 210 of these audio files
m=1;
cd 'my directory'
Extracted_files = dir;
nExtracted_files = length(Extracted_files);
for k = 1:nExtracted_files
[data,fs] = audioread(Extracted_files(k).name);
area = trapz(data)
A(m) = area;
m = m + 1;
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 4월 16일
plot (data)
Before you do that, you have to read from the file indicated by Extracted_files(k).name
area = trapz(x,y) %or should I use area(x,y)?
Your code does not define x or y, so ... ?

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 16일
whalelady - you mention that you are running into errors with
data,fs] = audioread(Extracted_files(k).name);
but you don't mention what the errors are. Is it
Error using audioread (line 74)
The filename specified was not found in the MATLAB path.
? When you call dir, some unexpected "files" may be added to your list (perhaps "." or ".."). I recommend that you add a filter like
Extracted_files = dir('*.wav');
or whatever extension makes sense for your files. Also, there is no need for the m variable as k can be used in its place. Your code could look like
cd 'my directory'
Extracted_files = dir('*.wav');
nExtracted_files = length(Extracted_files);
A = zeros(nExtracted_files,1);
for k = 1:nExtracted_files
[data,fs] = audioread(Extracted_files(k).name);
area = trapz(data)
A(k) = area;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Using audio files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by