How can I make multi parameters using syms, automatically?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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???
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!