I am trying to define a matrix with non-zero values from a data array that contains zero values.
Below is my attempt so far and have hit a block. When I "Regenerate sample matrix", my code is wrong. Obviously I am trying to access elements outside the range here.
If someone can take a look and make some suggestions that would be great.
The subscript of your adjusted matrix (which can have different size than your first one) in your last loop can not to be "i" but has to be one that is incremented when condition is true.
Same applies to the rest of your code. All can be done without any looping.
So as for sampleMatrixNz... just create a sparsed array and again use MxSetBlock. 4 to 5 lines of code but not more.
I'm not fully understanding how I would use MxSetBlock for my non-zero matrix. As I see it, the sample input (sparse array) contains zeros and would therefore not be of an equal matrix size to block set it into a new matrix.
Don't I need to iterate through my original matrix to find the zeros and skip them using a loop?
No, you do not iterate at all. Not a single time in your case. Just trust me when I am saying something. I am not telling things out of the blue but doing so as a result of having a clue (you see, I am a poet in addition).
Anyway, just take a look at full function list of AmiBroker manual. Together with Matrix(), MxSetBlock() and function for sparse array you would need just two additional functions (think before what you would need to do). That's it. Maximum 4 lines.