How change element of matrix in script?

Dmitry Ezhov shared this question 2 years ago
Answered

M={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}.

How change M(2,3) on value 1, to become M={{0,0,0,0},{0,0,1,0},{0,0,0,0},{0,0,0,0}}?

M(2,3)=1 not work.

SetValue work for list, not for matrix.

Comments (8)

photo
1

What do you need that for exactly?


Maybe use the spreadsheet for the numbers and define the matrix from that

photo
1

i wanted to do matrix (N+2)x(N+2) from matrix NxN in script

photo
photo
1

Hi, try :


Setvalue(M,Zip(Zip(if(r==2 && c==3,1,M(r,c)),c,1..4), r, 1..4))
and/or :

Setvalue(M,Zip(Zip(if(r==2 && c==3,1,M(r,c)),c,Sequence(k,k,1,Length(M))), r, Sequence(k,k,1,Length(M(1)))))

photo
1

Thanks!

Do not to create new topic, ask here. In Activity https://www.geogebra.org/m/ShPqmBCj on first input to InputBox is without errors. On second input or edit get error "Error in script at line 2 from object InputBox1", but calculate and visualisation is correct. How fix this error?

photo
photo
1

A workaround with script-list (Execute()) in the attachment.

======================================

@GGB-Team (as idea)

I think that an extension of the script command

SetValue(<list>,<ndx1>, <ndx2>..<ndxn>, <value>)

would be the best solution.

photo
1

Hi rami,

I need help with changing values from a list of numbers {61, 23, 23, 21, 5, 32, 23, 34}, eg to detect number 23, and replace with 64 so that the new list becomes {61, 64, 64, 21, 5, 32, 64, 34}.


Is there any Geogebra command to do this directly?

If not any solutions to help?


Regards,

lewws

photo
1

Zip(If(k==23, 64, k), k, {61, 23, 23, 21, 5, 32, 23, 34})

Script:

SetValue(<List>, Zip(If(k==23, 64, k), k, <List>))

photo
1

Many thanks Loco!Didn't realize Zip was so compact and powerful.

photo
© 2021 International GeoGebra Institute