String to Variable Name (str2var)

String to Variable Name (str2var) - Mensajes

#1 Publicado: 31/12/2022 2:33:45
Mark R Harris

Mark R Harris

5 me gusta en 90 mensajes.

Grupo: User

Is there a function or method that would allow a string (or variable name) located in a matrix element to be used as the name to define a variable?

Something like this:

Str2Var.png

Thank you!
#2 Publicado: 31/12/2022 4:28:45
Вячеслав Мезенцев

Вячеслав Мезенцев

1.558 me gusta en 1.868 mensajes.

Grupo: Moderator

Archivo no encontrado. Archivo no encontrado.

str2num_full.png
Russia ☭ forever, Viacheslav N. Mezentsev
A 4 usuarios les gustó este mensaje
Mark R Harris 31/12/2022 6:43:00, NDTM Amarasekera 31/12/2022 10:10:00, overlord 1/1/2023 15:20:00, sergio 31/12/2022 8:09:00
#3 Publicado: 31/12/2022 6:43:07
Mark R Harris

Mark R Harris

5 me gusta en 90 mensajes.

Grupo: User

Thank you so much uni!
#4 Publicado: 1/1/2023 12:51:50
Laurent Fournier

Laurent Fournier

9 me gusta en 66 mensajes.

Grupo: User

WOW!!!
#5 Publicado: 2/1/2023 6:31:00
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: Moderator

Wrote

Is there a function or method that would allow a string (or variable name) located in a matrix element to be used as the name to define a variable?



You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).

It converts boolean equations into assignments.

In the case of strings you still need to apply str2num()

Assign.sm (4,75 KiB) descargado 1334 vez(es).
assign.PNG
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
A 2 usuarios les gustó este mensaje
sergio 2/1/2023 7:35:00, Mark R Harris 2/1/2023 17:02:00
#6 Publicado: 4/1/2023 20:02:47
Mark R Harris

Mark R Harris

5 me gusta en 90 mensajes.

Grupo: User

Some odd behavior here. When the "=" evaluation is removed the Assign() function breaks:

Assign odd behaviour.png
Assign odd behaviour.sm (3,14 KiB) descargado 1312 vez(es).

Any thoughts?

I'm hoping to be able to assign multiple variables from a matrix like this:
Assign For Loop.png
Assign For Loop Broken.sm (5,11 KiB) descargado 1263 vez(es).
#7 Publicado: 4/1/2023 21:47:22
churichuro

churichuro

29 me gusta en 79 mensajes.

Grupo: User

a small workaround, could be to place the for inside a line command and return a false token value, it is not very clean but it works as far as I can see.



I think the assign command is not evaluated immediately, but has a delayed evaluation, which somehow only takes place after using the "=" symbol.
A 1 usuarios les gustó este mensaje
Mark R Harris 4/1/2023 22:04:00
#8 Publicado: 5/1/2023 11:30:01
overlord

overlord

600 me gusta en 1.381 mensajes.

Grupo: Moderator

Wrote

You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).


Assign() is a useful function and it doesn't need Maxima as you have indicated.
I don't (can't) use Maxima but I need Assign() sometimes.
And its codes have zero relation with Maxima functions.

This is why I suggested sometime ago that it could have relocated in another collective plugin.
CustomFunctions plugin is a good candidate for this purpose.
But I am not persistence, it is what it is.
Author of these plugins choose it this way.

Regards
A 1 usuarios les gustó este mensaje
Mark R Harris 5/1/2023 18:24:00
#9 Publicado: 5/1/2023 16:57:04
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: Moderator

Wrote

Some odd behavior here. When the "=" evaluation is removed the Assign() function breaks:

Assign odd behaviour.png
Assign odd behaviour.sm (3,14 KiB) descargado 1312 vez(es).

Any thoughts?

I'm hoping to be able to assign multiple variables from a matrix like this:
Assign For Loop.png
Assign For Loop Broken.sm (5,11 KiB) descargado 1263 vez(es).



Two hints:

- The Assign function needs to be executed in order to do it's work, either by assigning the result to some dummy variable or by requesting display of the result.
- You don't need a loop, Assign() can handle vector arguments

Blatt10.png
Blatt10.sm (5,31 KiB) descargado 1345 vez(es).
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
A 1 usuarios les gustó este mensaje
Mark R Harris 5/1/2023 18:24:00
#10 Publicado: 5/1/2023 17:22:41
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: Moderator

Wrote

Wrote

You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).


Assign() is a useful function and it doesn't need Maxima as you have indicated.
I don't (can't) use Maxima but I need Assign() sometimes.
And its codes have zero relation with Maxima functions.

This is why I suggested sometime ago that it could have relocated in another collective plugin.
CustomFunctions plugin is a good candidate for this purpose.
But I am not persistence, it is what it is.
Author of these plugins choose it this way.

Regards



In general I don't care where Assign() is defined. It is in the Maxima plugin, because I needed a neat way to make use of results from Maxima functions like algebraic or ode solvers.

Yet I don't think that it would be a good idea to remove functions from plugins, because this would break the dependency management of existing sheets.

I don't know what happens if the same function is defined in multiple plugins. Would SMath crash? If not, which definition is used if both plugins are installed? One would see this in the dynamic help, but how to control?

BTW, I think that some day I'll revisit the Maxima plugin and if I get some help with a linux development tool chain and work flow I could perhaps make the plugin work also under linux. But that would require at least two months of full time work without distractions, because I would need to learn C# anew from scratch.

If someone is a master in C# I am happy to assist in refactoring and bug fixing of the plugin by providing the specifications and unit tests.

I'd be more comfortable with python or javascript but to my knowledge these aren't options for making plugins.
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
A 1 usuarios les gustó este mensaje
Mark R Harris 5/1/2023 18:25:00
#11 Publicado: 6/1/2023 2:15:05
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: User

Hi. This could be another option.

Clipboard01.png

MyAssign 2.sm (10,52 KiB) descargado 1334 vez(es).

Best regards.
Alvaro.
A 7 usuarios les gustó este mensaje
⚜ Kenny Lemens, P.E. ᵂᴵ 27/2/2023 12:19:00, Вячеслав Мезенцев 6/1/2023 7:07:00, NDTM Amarasekera 6/1/2023 12:57:00, sergio 6/1/2023 14:23:00, churichuro 6/1/2023 16:19:00, bdrunagle 6/1/2023 16:21:00, Mark R Harris 6/1/2023 16:41:00
#12 Publicado: 6/1/2023 16:25:18
churichuro

churichuro

29 me gusta en 79 mensajes.

Grupo: User

@Razonar, as usual with you, you give imaginative and useful solutions, it's great when people share their knowledge and help others, and with such a high technical level. thanks and congratulations.

I have a folder on my computer exclusively for the spreadsheets you share.
A 2 usuarios les gustó este mensaje
Mark R Harris 6/1/2023 17:15:00, Alvaro 6/1/2023 23:10:00
#13 Publicado: 6/1/2023 16:42:15
Arie

Arie

94 me gusta en 285 mensajes.

Grupo: User

In the event you may want to add descriptions to these definitions... a related thread:
https://en.smath.com/forum/yaf_postst23228_Assign-Description-to-Variable.aspx

It's a work around, but potentially useful.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
A 3 usuarios les gustó este mensaje
Alvaro 6/1/2023 23:10:00, sergio 7/1/2023 7:09:00, Mark R Harris 6/1/2023 16:50:00
#14 Publicado: 6/1/2023 16:43:00
Mark R Harris

Mark R Harris

5 me gusta en 90 mensajes.

Grupo: User

Wrote

@Razonar, as usual with you, you give imaginative and useful solutions, it's great when people share their knowledge and help others, and with such a high technical level. thanks and congratulations.

I have a folder on my computer exclusively for the spreadsheets you share.



Yes indeed. Likewise. What churichuro said!
A 1 usuarios les gustó este mensaje
Alvaro 6/1/2023 23:10:00
#15 Publicado: 6/1/2023 23:11:34
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: User

Thanks guys. I sincerely appreciate that.

Best regards.
Alvaro.
  • Nuevos mensajes
  • Sin mensajes nuevos