Logarithmic summation of cell array
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Karthik Brs
el 29 de Oct. de 2015
Comentada: Stephen23
el 30 de Oct. de 2015
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!
Respuesta aceptada
Geoff Hayes
el 29 de Oct. de 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?
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!