Jump to content

Matrix : practical reading /printing


alr77

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,

 

 

Link to comment
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
Link to comment
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 + + +

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...