I need assistance, actually I have a matrix b=2500x21, which is imaginary part of a FRF signal. I want to find peaks for every column, each column represents accelerometer response at different location of a beam. The following code i have written.
for i=1:21
pks(:,i)=findpeaks(b(:,i))
end
pks(:,i)=pks;
Problem is that, the matrix pks just stores last iteration value. I want that all the peak values after every iteration will be stored in a single matrix.
Can any body having suggestions?

8 comentarios

madhan ravi
madhan ravi el 31 de Ag. de 2018
Editada: madhan ravi el 31 de Ag. de 2018
Just format the code using the code button. So that it’s easy for others to read your code.
Walter Roberson
Walter Roberson el 31 de Ag. de 2018
After your for loop, i will be left at its last value, 21. Then your final statement there would be equivalent to
pks(:,21) = pks;
which tries to store the entire pks array into a single location in the pks array. I am having difficulty coming up with any circumstance under which that could work without giving an error message.
I suspect that the for loop will generate an error, as most of the time the different columns of signal will lead to a different number of peaks being found, leading to errors when you tried to store the different vector lengths into the same array.
Stephen23
Stephen23 el 31 de Ag. de 2018
What is the purpose of this?:
pks(:,i)=pks;
jonas
jonas el 31 de Ag. de 2018
Editada: jonas el 31 de Ag. de 2018
I'm surprised you can even run your code. I'd expect a crash unless you find the same number of peaks in each iteration.
Store output in a preallocated cell array instead.
Ayisha Nayyar
Ayisha Nayyar el 31 de Ag. de 2018
Actually its working, it generates a matrix of length 5x21, the problem is that matrix contains peak values in 1st and last column, rest of the columns are zero. I want that matrix containing peak values at 21 different locations.......these peak values are appeared in the command window, but i am unable to store them in matrix properly.
Ayisha Nayyar
Ayisha Nayyar el 31 de Ag. de 2018
Shortly, i should say that every next iteration value overrides the previous one....
jonas
jonas el 31 de Ag. de 2018
Editada: jonas el 31 de Ag. de 2018
Can you attach the data? No point in guessing. I find it hard to believe no error is returned.
Stephen23
Stephen23 el 31 de Ag. de 2018
Ayisha Nayyar's "Answer" moved here and formatted correctly:
Hi jonas, I have attached the file, now follow the code and see the results please.
for i=1:21
pks(:,i)=findpeaks(b(:,i))
end
pks(:,i)=pks;

Iniciar sesión para comentar.

 Respuesta aceptada

jonas
jonas el 31 de Ag. de 2018
Editada: jonas el 31 de Ag. de 2018

0 votos

As expected, your code returned the error
Unable to perform assignment because the size of the left side is 3-by-1 and the size of the right side is 6-by-1.
...because of reasons already listed multiple times in the comments.
You can solve this by storing the data in a cell array.
T=readtable('b.xlsx');
b=table2array(T);
pks=cell(21,1);
for i=1:21
pks{i}=findpeaks(b(:,i))
end
pks =
21×1 cell array
{6×1 double}
{6×1 double}
{6×1 double}
{6×1 double}
{7×1 double}
{6×1 double}
{5×1 double}
{7×1 double}
...

3 comentarios

Ayisha Nayyar
Ayisha Nayyar el 31 de Ag. de 2018
Thanks Jonas, i am partially satisfied by your answer, but as i know that for every column of my matrix 'b', I could have at least five peaks. The values arranged in this format is providing only one peak value of each column of 'b'.
jonas
jonas el 31 de Ag. de 2018
Editada: jonas el 31 de Ag. de 2018
No. You can access the peak values in the first column by:
pks{1}
ans =
1.0e-04 *
0.2180
0.0216
0.0040
0.0008
0.0001
-0.0000
As you can see, there are 6 values. Some peak values have extremely small prominence. You can adjust the 'MinPeakProminence' argument of findpeaks if you wish to exclude those.
Further reading on accessing data in cell arrays ( link ).
Ayisha Nayyar
Ayisha Nayyar el 31 de Ag. de 2018
thanks again

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2015a

Etiquetas

Preguntada:

el 31 de Ag. de 2018

Comentada:

el 31 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by