Create a incremented 2D matrix
이전 댓글 표시
I am trying to add values to a matrix of 2 dimensions. The rows of toothCount are the values that holds the number of times a specific condition is met. The columns of toothCount are a reference to the offset in which the conidtion is true. I need this to build an array. Here is the working 1D version:
toothCount((find(tmpVec==1)))=toothCount((find(tmpVec==1)))+ones(size(find(tmpVec==1)));
%tmpVec is the condition that must be met in order for that row of toothCount to increment.
How do I go about turning this into a growing 2 dimensional array? This call is within a double for loop, so I want the parent for loop to increment the column and the condition & child for loop take care of the values of the rows (as it is doing in the above 1D version). Is there an easy way to do this?
채택된 답변
추가 답변 (1개)
A simpler expression for your 1D case would be:
toothCount(tempVec == 1) = toothCount(tempVec == 1) + 1;
Assuming, that tempVec (now tempMat or better a name that actually mean something) is now a matrix the same size and dimension as toothCount the above will work for any dimension.
If not, you need to give more details on what tempVec is.
edit: I'm not sure why you've got a 'concatenation' tag since your example does not involve any concatenation.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!