String to Variable Name (str2var)

String to Variable Name (str2var) - Messages

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

Mark R Harris

4 likes in 90 posts.

Group: 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 Posted: 12/31/2022 4:28:45 AM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

File not found. File not found.

str2num_full.png
Russia ☭ forever, Viacheslav N. Mezentsev
4 users liked this post
Mark R Harris 12/31/2022 6:43:00 AM, NDTM Amarasekera 12/31/2022 10:10:00 AM, overlord 1/1/2023 3:20:00 PM, sergio 12/31/2022 8:09:00 AM
#3 Posted: 12/31/2022 6:43:07 AM
Mark R Harris

Mark R Harris

4 likes in 90 posts.

Group: User

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

Laurent Fournier

9 likes in 66 posts.

Group: User

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

Martin Kraska

1222 likes in 2150 posts.

Group: 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 KiB) downloaded 27 time(s).
assign.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
2 users liked this post
sergio 1/2/2023 7:35:00 AM, Mark R Harris 1/2/2023 5:02:00 PM
#6 Posted: 1/4/2023 8:02:47 PM
Mark R Harris

Mark R Harris

4 likes in 90 posts.

Group: User

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

Assign odd behaviour.png
Assign odd behaviour.sm (3 KiB) downloaded 12 time(s).

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 KiB) downloaded 20 time(s).
#7 Posted: 1/4/2023 9:47:22 PM
churichuro

churichuro

28 likes in 79 posts.

Group: 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.
1 users liked this post
Mark R Harris 1/4/2023 10:04:00 PM
#8 Posted: 1/5/2023 11:30:01 AM
overlord

overlord

549 likes in 1332 posts.

Group: 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
1 users liked this post
Mark R Harris 1/5/2023 6:24:00 PM
#9 Posted: 1/5/2023 4:57:04 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

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

Assign odd behaviour.png
Assign odd behaviour.sm (3 KiB) downloaded 12 time(s).

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 KiB) downloaded 20 time(s).



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 KiB) downloaded 19 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Mark R Harris 1/5/2023 6:24:00 PM
#10 Posted: 1/5/2023 5:22:41 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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.
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Mark R Harris 1/5/2023 6:25:00 PM
#11 Posted: 1/6/2023 2:15:05 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Hi. This could be another option.

Clipboard01.png

MyAssign 2.sm (10 KiB) downloaded 27 time(s).

Best regards.
Alvaro.
7 users liked this post
⚜ Kenny Lemens, P.E. ᵂᴵ 2/27/2023 12:19:00 PM, Вячеслав Мезенцев 1/6/2023 7:07:00 AM, NDTM Amarasekera 1/6/2023 12:57:00 PM, sergio 1/6/2023 2:23:00 PM, churichuro 1/6/2023 4:19:00 PM, bdrunagle 1/6/2023 4:21:00 PM, Mark R Harris 1/6/2023 4:41:00 PM
#12 Posted: 1/6/2023 4:25:18 PM
churichuro

churichuro

28 likes in 79 posts.

Group: 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.
2 users liked this post
Mark R Harris 1/6/2023 5:15:00 PM, Alvaro Diaz Falconi 1/6/2023 11:10:00 PM
#13 Posted: 1/6/2023 4:42:15 PM
Arie

Arie

93 likes in 285 posts.

Group: 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
3 users liked this post
Alvaro Diaz Falconi 1/6/2023 11:10:00 PM, sergio 1/7/2023 7:09:00 AM, Mark R Harris 1/6/2023 4:50:00 PM
#14 Posted: 1/6/2023 4:43:00 PM
Mark R Harris

Mark R Harris

4 likes in 90 posts.

Group: 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!
1 users liked this post
Alvaro Diaz Falconi 1/6/2023 11:10:00 PM
#15 Posted: 1/6/2023 11:11:34 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Thanks guys. I sincerely appreciate that.

Best regards.
Alvaro.
  • New Posts New Posts
  • No New Posts No New Posts