How can I make multi parameters using syms, automatically?

1 vue (au cours des 30 derniers jours)
연승 김
연승 김 le 16 Mar 2021
Commenté : Star Strider le 16 Mar 2021
I want to make mulit parameters using syms.
For example
syms 'p%d' [2 2]
This code make matrix [p11, p12 ; p21, p22].
And I want to input a value in the symbolic variables.
Like this
p11 = 1
p12 = 2
p21 = 3
p22 = 4.
I can input a value each. But I want to automatic.
Because as the instance expand, it's hard to input a value each...
syms 'p%d' [20 10]
If I use this code, I have to coding 200 paramaters one by one.
How I can this automatically???

Réponse acceptée

Star Strider
Star Strider le 16 Mar 2021
One approach:
For the (2x2) example:
syms p
P = sym('p%d', [2 2])
v = [1 2 3 4];
P = reshape(v,[],size(P,1)).';
and for the extended (20x10) result:
syms p
P = sym('p%d', [20 10]);
v = 1:200;
P = reshape(v,[],size(P,1)).';
Experiment to get the result you want.
  2 commentaires
연승 김
연승 김 le 16 Mar 2021
Thank you!! it works well!!^^
Star Strider
Star Strider le 16 Mar 2021
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by