How to buffer old columns in a matrix when new columns are added

1 vue (au cours des 30 derniers jours)
Jack Olmstead
Jack Olmstead le 9 Oct 2017
Commenté : Jack Olmstead le 9 Oct 2017
I'm writing a loop where I'm continually adding to an m x n matrix called histoMat on each iteration with a row vector called reposit. reposit is re-initialized and differs in size from iteration to iteration, but histoMat only grows, like so:
histoMat = [histoMat; reposit]
Unfortunately, I can't initialize the size of histoMat before the loop begins, since I don't know the maximum size of any single reposit row. As you can see, because reposit is very rarely the same size as it was the iteration before, I'm getting a vertcat dimension error when I try to append on to histoMat. For example, this will give me an error:
reposit = [1 2 3 4 5]
histoMat = [1 2 3]
histoMat = [histoMat; reposit]
Error using vertcat
Dimensions of matricies being concatenated are not consistent.
My question is: Is there any good way to buffer the bottom of histoMat with zeros whenever needed in order to avoid this? Here's an ideal example of what I'd like to accomplish:
reposit = [1 2 3 4 5]
histoMat = [1 2 3]
histoMat = [histoMat; reposit]
histoMat = [1 2 3 0 0
1 2 3 4 5]

Réponse acceptée

James Tursa
James Tursa le 9 Oct 2017
Modifié(e) : James Tursa le 9 Oct 2017
Append reposit this way:
histoMat(end+1,1:numel(reposit)) = reposit;

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by