필터 지우기
필터 지우기

Add a dynamic amount of symbolic variables into a script

조회 수: 1 (최근 30일)
Connor LeClaire
Connor LeClaire 2021년 10월 21일
답변: Paul 2021년 10월 21일
I am attempting to add a number of symbolic variables dynamically for a script.
The script will get an input from the user about how many joints they are inputting in for some robotic manipulation calculations. Based on this I would like to insert a number of symbolic variables (equal to the amount specified at the initial input).
Is there a way to do this that isn't creating a bunch of variables in storage like:
syms v1 v2 v3 v4 v5 v6 v7 v8 v9 v9 %...
variables = [v1 v2 v3 v4 v5 v6 v7 v8 v9] %...
numvars = input('How many joints would you like to enter: ');
for i=1:numvars
%Do something
end

채택된 답변

Paul
Paul 2021년 10월 21일
numvars = 5; % for example
V = sym('V',[1 numvars])
V = 

추가 답변 (1개)

Connor LeClaire
Connor LeClaire 2021년 10월 21일
After further research and help from a friend, here is the answer:
numVars = input('Enter how many joints: ');
variables = sym(zeros(1,numVars));
for i=1:numVars
variables(i) = sym("V"+ num2str(i));
end
disp(variables);

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by