Logarithmic summation of cell array
14 views (last 30 days)
Show older comments
Hello everyone!
I currently have a 1*2 cell array. The cell array might also be additional fields. I have attached .mat file containing the variable with this query. The data in the given cell array contains the sound powers in 'db'. I am required to perform the logarithmic addition of all column vectors(100*1) in my cell array such that the resulting vector is of log. sum of all the column vectors, in my case(100*1). I am finding it difficult to perform this operation.
Thank you in advance!
Accepted Answer
Geoff Hayes
on 29 Oct 2015
Karthik - sometimes it helps to use the MATLAB debugger and step through the code to see what is happening at each line. Though trying to run the above fails immediately because of the way in which you are trying to iterate over the tempLW array. See http://www.mathworks.com/help/matlab/ref/for.html to understand how the for loop is constructed which would mean that your code would change to
for k=1:length(tempLw)
Using i and j as indexing variables are discouraged since they are also used by MATLAB to represent the imaginary number. Also, you are missing a bracket on your second line of code and so should be
TotalSoundPower = 10*log(sum(tempLw{k}));
Note also the braces used instead of brackets when accessing the column of data in the tempLW cell array.
So the above changes will get the code to work, but is the above really what you want? Do you want to sum all the decibel values from the first column and then do the 10*log10 on that sum? Is this giving you the value that you want? Then, what about the second column as you overwrite the TotalSoundPower from the first iteration of the loop?
More Answers (0)
See Also
Categories
Find more on Logical 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!