Create a incremented 2D matrix
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (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.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!