Finding area of a plot/graph in a for loop and save answer into array
Show older comments
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 Comments
Walter Roberson
on 16 Apr 2020
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 ... ?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!