Jump to content
alr77

Matrix : practical reading /printing

Recommended Posts

Dear all,

 

Sorry if my question looks naive, as you're all surely usual with this : matrix reading /printing.

But i'd like to "printf" it element by element. Usually, generally a matrix looks like : matrix M[r][c] -> then your iter through. eg : print(M[1][1]+"\n");

But here in Hou it is : matrix M

Yes printf() prints the thing but the whole thing. Then, how to read elements one by one separatly, please? i humbly dunno.

Am usual with this practice in other languages because Matrices could be used as a fantastic "Chest" to store values, compiling vectors pack, and on and on...

 

So any advices to this practical question are welcome.

 

Thank you a lot.

Bests,

 

 

Share this post


Link to post
Share on other sites

For some reason M[1][1] is not working in VEX, but you can always use getcomp(M, 1, 1).

for (int row = 0; row < 4; row++)
{
    string out = "";
    for (int col = 0; col < 4; col++)
    {
        float value = getcomp(4@test, row, col);
        out += sprintf("%g  ", value);
    }
    printf(out + "\n");
} 

Matrices in Houdini are not m×n arrays, but 4-, 9- and 16-float "vectors". They rarely used as storage, as there is one-dimension arrays available for this purpose. Python is generally used for more sophisticated arrays manipulation. NumPy available by default.

import numpy

node = hou.pwd()
geo = node.geometry()

mat = geo.floatListAttribValue('test');
val = numpy.array(mat).reshape((4, 4))

print(val)

print_matrix.hipnc

  • Like 1

Share this post


Link to post
Share on other sites

Dear F1,

Thank you for explanations, because i've found myself in front of a locked door which finally was more like an illusion as you're explaining the classic "for" iteration is working. Thus we can say even if the academic notation : M[][] doesn't work, its functionality is implicitly embeded inside DOGMATIC 2x2 3x3 or 4x4...so...perfect.

 

i deduce then the reverse getcomp() is setcomp().

I can now, sort, store , arrage datas inside. GR8 !

Thank you twice F1, and enjoy the week end.

bests,

alr + + +

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×