Logarithmic summation of cell array

조회 수: 14 (최근 30일)
Karthik Brs
Karthik Brs 2015년 10월 29일
댓글: Stephen23 2015년 10월 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