4

Is there a way I can use a command that selects a matrix to use based on a variable?
Need in this /
:If (way to select a matrix based on what variable L equals) (E,F)=1:Output E,F,"O

I don't want to make a specific go-to for every single matrix I need. This is for creating maps with the matrix in case anyone has a better way.

chiliNUT
  • 18,989
  • 14
  • 66
  • 106
xclamation
  • 41
  • 1
  • Maybe rethink using matrices in the way you are... Would it be possible to store your data in a different way? Possibly one matrix? The thing about TI-Basic as a whole is using a really crappy array of data types and methods to make something cool. I guess it would help us if you gave us more context about your problem so we could propose a different solution. – bearacuda13 Nov 11 '18 at 18:00

1 Answers1

2

If i understand correctly you want to get the value from a certain matrix, chosen dynamically depending on the value of a variable. You can kinda do this by putting the names of the matrices into a string, then grab a substring of the string, using sub(, at a dynamic offset, based on L, and then feeding that string into expr( to get a reference to the matrix, ie

:"[A][B][C]"->Str1, sub(Str1,2,1) yields "[B]", expr("[B]") yields Matrix B...so 2 maps to [B]. TI considers the symbol [A] (and all the other matrix vars) to be a single character, so "[A][B][C]" is a 3 character string.

Note that all of the matrix vars need to be input from the MATRIX menu (including inside the string). Typing in the individual [ A ] chracters will not work.

Also note you can't grab indexes off of a matrix returned with expr (ie expr("[A]")(1,2) so you need an extra matrix (I used [J]) to store the result.

For example

:"MAKE SOME MATRICES"
:[[1,2][3,4]]->[A]
:[[5,6][7,8]]->[B]
:[[9,10],[11,12]]->[C]
:"SAMPLE L VALUE"
:2->L
:"STORE REFERENCES TO THE"
:"MATRICES IN A STRING"
:"[A][B][C]"->Str1
:expr(sub(Str1, L, 1))->[J]
:"SHOWS 6"
:[J](1,2)

so then proceed normally with [J]

:If [J](E,F)
: "DO WHATEVER

Tested on an 84 SE, I assume it would work the same for anything in that family, except IIRC some older models only have matrices A-F

chiliNUT
  • 18,989
  • 14
  • 66
  • 106