Showing results for 
Search instead for 
Do you mean 

Set Matrix Center Snippet

by on ‎12-09-2015 11:52 AM - edited on ‎02-24-2020 04:51 AM by Community Manager (1,497 Views)

Download model


This model demonstrates how to change the center value in a matrix. The model is a snippet and is intended to be used as part of a workflow (placed into a larger model) and, as such, does not have input/output port operators.


Provide the 'New Value' port of the 'Set Center Value' submodel with the desired value, enter a filename for the output matrix that will have this new center value, and you're done. The snippet will take whatever input matrix has been selected for Custom Matrix Input, will change the center value to New Value and write the resulting new matrix to Matrix File Output. The Inputs and Outputs can be removed to hook the snippet up into a larger model workflow.


You can see this snippet being used in a larger Model in the Article entitled "Blended Filters". There it is used to initialise another matrix that is the same size as the main matrix selected by the user, but which contains all zeros apart from the center value, which is set to one (via the New Value port shown below).


Set Center Value submodel
Set Matrix Element submodel


Input parameters:

Set Center Value.New Value: the desired center value (Scalar, Table, Matrix, Raster)

Matrix Output.Filename: name of the output matrix


on ‎08-07-2016 07:41 PM

Slick and works great!


There's a couple tricks in the 'Set Matrix Element' submodel that may not be obvious to noobs like myself so don't mind if l point them out.


(1) If a matrix was reshaped as a vector of N elements, then RowNum*Cols+ColNum yields an index for a particular matrix element. 


(2) The InitialValue port on the 'Dynamic Matrix Input (Series)' operator assumes a zerod initial matrix. If that's not the case, then updates will fail. Users can modify the model to include an additional port to set InitialValue to the value to be replaced.


The puzzling part is how the index to the Nth item (a scalar) is compared/equated to the output of the 'Dynamic Matrix Input (Series)' operator (a Matrix). So that it can compare values of the same data-type, I suspect the engine simply pulls the InitialValue scalar from the input side of the 'Dynamic Matrix Input (Series)' operator. 


Who'd have guessed?