Logarithmic summation of cell array

13 次查看(过去 30 天)
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!

采纳的回答

Geoff Hayes
Geoff Hayes 2015-10-29
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?
  2 个评论
Karthik Brs
Karthik Brs 2015-10-29
Hello Mr. Hayes, Thanks for the reply! I am not sure about how to add the decibel values. The code which I have included is the one which I found for excel. Would be glad if you can let me know the correct way to add the decibel value. All that I know is that I have to perform a logarithmic sum of decibel values as the decibel values cannot be added normally.
Karthik Brs
Karthik Brs 2015-10-30
The addition must be performed according to the equation as can be seen in the attached figure 'Formula.png'.
The 'L1' and 'L2' in the figure in my case represents the elements of cell array(column-wise). Please help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by