SMath Studio Forum
»
SMath Studio
»
Questions
»
String to Variable Name (str2var)
Rank: Advanced Member Groups: Registered
Joined: 01/04/2020(UTC) Posts: 85 Location: Wellington Was thanked: 4 time(s) in 3 post(s)
|
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: Thank you! Edited by user 31 December 2022 10:24:54(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 10/11/2010(UTC) Posts: 1,494 Was thanked: 1274 time(s) in 745 post(s)
|
|
Russia ☭ forever Viacheslav N. Mezentsev |
4 users thanked uni for this useful post.
|
on 31/12/2022(UTC), on 31/12/2022(UTC), on 31/12/2022(UTC), on 01/01/2023(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 01/04/2020(UTC) Posts: 85 Location: Wellington Was thanked: 4 time(s) in 3 post(s)
|
Thank you so much uni! Edited by user 31 December 2022 12:49:57(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 13/09/2011(UTC) Posts: 63 Location: Kolkata
Was thanked: 9 time(s) in 9 post(s)
|
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,986 Was thanked: 1124 time(s) in 721 post(s)
|
Originally Posted by: marks2c 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 (5kb) downloaded 12 time(s).Edited by user 02 January 2023 13:04:16(UTC)
| Reason: Not specified |
|
2 users thanked mkraska for this useful post.
|
on 02/01/2023(UTC), on 02/01/2023(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 01/04/2020(UTC) Posts: 85 Location: Wellington Was thanked: 4 time(s) in 3 post(s)
|
Some odd behavior here. When the "=" evaluation is removed the Assign() function breaks: Assign odd behaviour.sm (4kb) downloaded 1 time(s).Any thoughts? I'm hoping to be able to assign multiple variables from a matrix like this: Assign For Loop Broken.sm (6kb) downloaded 5 time(s).Edited by user 05 January 2023 02:36:10(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 27/03/2019(UTC) Posts: 75 Location: coah Was thanked: 27 time(s) in 22 post(s)
|
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. Edited by user 05 January 2023 03:49:54(UTC)
| Reason: Not specified
|
1 user thanked churichuro for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,128 Was thanked: 509 time(s) in 339 post(s)
|
Originally Posted by: mkraska 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 user thanked overlord for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,986 Was thanked: 1124 time(s) in 721 post(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.sm (6kb) downloaded 3 time(s). |
|
1 user thanked mkraska for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,986 Was thanked: 1124 time(s) in 721 post(s)
|
Originally Posted by: overlord Originally Posted by: mkraska 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. |
|
1 user thanked mkraska for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 28/08/2014(UTC) Posts: 1,356 Was thanked: 815 time(s) in 516 post(s)
|
Hi. This could be another option. MyAssign 2.sm (11kb) downloaded 14 time(s).Best regards. Alvaro. Edited by user 06 January 2023 11:44:35(UTC)
| Reason: Example added.
|
7 users thanked Razonar for this useful post.
|
on 06/01/2023(UTC), on 06/01/2023(UTC), on 06/01/2023(UTC), on 06/01/2023(UTC), on 06/01/2023(UTC), on 06/01/2023(UTC), on 27/02/2023(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 27/03/2019(UTC) Posts: 75 Location: coah Was thanked: 27 time(s) in 22 post(s)
|
@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. Edited by user 06 January 2023 22:28:08(UTC)
| Reason: Not specified
|
2 users thanked churichuro for this useful post.
|
on 06/01/2023(UTC), on 07/01/2023(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/03/2016(UTC) Posts: 276 Was thanked: 91 time(s) in 57 post(s)
|
|
|
3 users thanked alyles for this useful post.
|
on 06/01/2023(UTC), on 07/01/2023(UTC), on 07/01/2023(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 01/04/2020(UTC) Posts: 85 Location: Wellington Was thanked: 4 time(s) in 3 post(s)
|
Originally Posted by: churichuro @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 user thanked marks2c for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 28/08/2014(UTC) Posts: 1,356 Was thanked: 815 time(s) in 516 post(s)
|
Thanks guys. I sincerely appreciate that.
Best regards. Alvaro.
|
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
String to Variable Name (str2var)
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.