How to buffer old columns in a matrix when new columns are added
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
James Tursa
2017 年 10 月 9 日
編集済み: James Tursa
2017 年 10 月 9 日
Append reposit this way:
histoMat(end+1,1:numel(reposit)) = reposit;
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!