Create n symbolic variables
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi, I would like to know if there's a way to create n differente symbolic variables (n is an input). Thank's in advanced
채택된 답변
madhan ravi
2018년 10월 25일
편집: madhan ravi
2018년 10월 25일
EDITED
n=input('value of n?')
syms(sym('a',[1 n]))
a=(sym('a',[1 n])) %storing symbolic variables in a vector for convenience and also to use indexing
command window displays:
value of n?10
n =
10
a =
[ a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]
>> a(1:6)
ans =
[ a1, a2, a3, a4, a5, a6]
>>
The above is strictly not recommended though please see http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
댓글 수: 9
madhan ravi
2018년 10월 25일
The above shows an example of creating n symbolic variables
madhan ravi
2018년 10월 25일
편집: madhan ravi
2018년 10월 25일
If it’s what you want accept the answer so other people know the question is solved else let know
Note that this creates a single variable, A, that contains a vector of symbolic expressions that refer to symbolic variables that live in the symbolic engine, same as if you had done
A = [sym('A1'), sym('A2'), sym('A3'), ... sym('A20')];
The code does not create variables A1, A2, A3, ... A20 at the MATLAB level. You will not see them in the workspace; you will only see A in the workspace.
If you need to create them at the MATLAB level, then chances are that you should be coding differently.
madhan ravi
2018년 10월 25일
Yes sir I thought the OP asked to simply create variable to be used further in mathematical equations
madhan ravi
2018년 10월 25일
Edited the answer sir Walter, thank you for pointing it out
syms(sym('a',[1 n]))
That does work to create the variables in the MATLAB workspace, but any time you are creating a variable number of variables in the MATLAB workspace you should stop yourself and ask if it is strictly necessary to do so, as there is almost always a better way.
madhan ravi
2018년 10월 25일
Oh yes sir Walter didn’t think of it actually thank you once again
one plus one is two
2018년 11월 20일
Sorry for the late, thank you so much for your help!
madhan ravi
2018년 11월 20일
Anytime :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
