필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Jack Olmstead
Jack Olmstead 2017년 10월 9일
댓글: Jack Olmstead 2017년 10월 9일
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]

채택된 답변

James Tursa
James Tursa 2017년 10월 9일
편집: James Tursa 2017년 10월 9일
Append reposit this way:
histoMat(end+1,1:numel(reposit)) = reposit;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by