How to store vectors of unequal sizes, created by a for loop in a cell?

2 views (last 30 days)
Hello all,
I am trying to use the pkurtosis function within a for loop on my Pitch_BL 1-D time sereis vector as shown below. However, in the output, SK_BL is a different length for each iteration of the loop, and thus makes it impossible to store all of the outputs of SK_BL into a single matrix.
I am attempting to get around this by having the for loop run the pkurtosis function 25 different times, and for each time, store the output variables in a cell, SK_BL_Cell(:,k), thus allowing vectors of unequal lengths to be concatenated together.
Unfortunatley, my code is giving me an error,"Index in position 2 exceeds array bounds (must not exceed 1)", and I was wondering if someone could help.
Thanks in advance.
for k = 1:25
[SK_BL, F_out_BL, Thresh_BL] = pkurtosis(Pitch_BL(:,k),Fs,wc_BL(k,:),'ConfidenceLevel',0.95);
SK_BL_Cell(:,k) = num2cell(SK_BL(:,k));
F_out_BL_Cell(:,k) =num2cell(F_out_BL(:,k));
Thresh_BL_Cell(:,k) = num2cell(Thresh_BL(k,:));
end

Accepted Answer

Star Strider
Star Strider on 27 May 2019
I would just do something like this:
SK_BL_Cell{k} = SK_BL(:,k);
F_out_BL_Cell{k} = F_out_BL(:,k);
Thresh_BL_Cell{k} = Thresh_BL(k,:);
  2 Comments
Brittny Freeman
Brittny Freeman on 27 May 2019
Thanks for getting back to me Star, I've yet to pose a question that you couldn't answer!
I was able to get it to work, just had to make one small adjustment as shown below:
SK_BL_Cell{k} = SK_BL;
F_out_BL_Cell{k} = F_out_BL;
Thresh_BL_Cell{k} = Thresh_BL;
The answer was so easy, don't know why I didn't see it beforehand.
Star Strider
Star Strider on 27 May 2019
My pleasure.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!