How to make matrix after using findpeaks?

8 views (last 30 days)
Hi,now i have a question about cell after using "findpeaks". Its very simple question, i guess. I used "findpeaks" and now i have a cell data like follows.
for k=1:10
B{k}=findpeaks(value(:,k),'NPeaks',6);
end
And now cell{B} is consist with some data like this:
[1, 0.35315, 0.35267, 0.25845, 0.14570, 0.14683] [1, 0.25243, 0.19255, 0.14261] [1, 0.28165, 0.17765, 0.14319, 0.12926] .....
Then i want to convert these data to array(matrix) like follows.
1 1 1
0.35315 0.25243 0.28165
0.35267 0.19255 0.17765
0.25845 0.14261 0.14319
0.14570 0.12926
0.14683
if you some idea to solve this problem, please give me some advice. thanks.
  1 Comment
KSSV
KSSV on 25 Sep 2017
YOu can convert cell B to a matrix if every cell has same number of elements, else you cannot convert. Read about cell2mat.

Sign in to comment.

Accepted Answer

OCDER
OCDER on 26 Sep 2017
This is one way to do this, but you have to fill in the unused space with something like NaN.
C{1} = [1, 0.35315, 0.35267, 0.25845, 0.14570, 0.14683];
C{2} = [1, 0.25243, 0.19255, 0.14261];
C{3} = [1, 0.28165, 0.17765, 0.14319, 0.12926];
MaxLen = max(cellfun(@numel, C));
D = cell2mat(cellfun(@(x) [x(:); NaN(MaxLen - numel(x), 1)], C, 'UniformOutput', false));
D =
1.0000 1.0000 1.0000
0.3532 0.2524 0.2817
0.3527 0.1926 0.1777
0.2585 0.1426 0.1432
0.1457 NaN 0.1293
0.1468 NaN NaN
  1 Comment
Sayaka Kamata
Sayaka Kamata on 27 Sep 2017
Thanks a lot! The problem was about the replacement of empty number!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!