필터 지우기
필터 지우기

How to `subs` with both scalar variable and arrays?

조회 수: 4 (최근 30일)
wei zhang
wei zhang 2020년 6월 22일
답변: madhan ravi 2020년 6월 22일
I am evaluating some expression with subs. I need to input a scalar variable and an array. But it always give errors as I substitute them in one command as below.
e.g.
syms x
syms t [1 3]
g = x+t1+t2;
result = subs(g,{x,t},{1,[1,2,3]});
This is a mini case for my problem. How to solve this error? Must I subs the variables in several independent steps?

채택된 답변

madhan ravi
madhan ravi 2020년 6월 22일
syms x
syms t [1 3]
g = x+t1+t2;
t_vars = num2cell(t);
t_vals = num2cell(1:3);
result = subs(g,{x,t_vars{:}},{1,t_vals{:}})

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by