Finding area of a plot/graph in a for loop and save answer into array
2 ビュー (過去 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
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
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 Center および File Exchange で Using audio files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!