필터 지우기
필터 지우기

How can I make multi parameters using syms, automatically?

조회 수: 1 (최근 30일)
연승 김
연승 김 2021년 3월 16일
댓글: Star Strider 2021년 3월 16일
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???

채택된 답변

Star Strider
Star Strider 2021년 3월 16일
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
연승 김
연승 김 2021년 3월 16일
Thank you!! it works well!!^^
Star Strider
Star Strider 2021년 3월 16일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by