How to buffer old columns in a matrix when new columns are added
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Jack Olmstead
il 9 Ott 2017
Commentato: Jack Olmstead
il 9 Ott 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]
0 Commenti
Risposta accettata
James Tursa
il 9 Ott 2017
Modificato: James Tursa
il 9 Ott 2017
Append reposit this way:
histoMat(end+1,1:numel(reposit)) = reposit;
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!