Creating a symbolic array
5 次查看(过去 30 天)
显示 更早的评论
When I tried to create an array consisting of expressions in terms of a symbolic variable I get the error message
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
But I don't want to evaluate the expressions at a particular value. Instead I want expressions in terms of the symbolic variable q. Does anyone have suggestions regarding how this can be done?
syms q
a = [];
for i = 1:5
for j = 1:5
a(i,j) =q;
end
end
0 个评论
采纳的回答
更多回答(2 个)
Stephan
2020-11-24
编辑:Stephan
2020-11-24
>> q = sym('q', [5, 5])
q =
[ q1_1, q1_2, q1_3, q1_4, q1_5]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, q3_4, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]
>> whos q
Name Size Bytes Class Attributes
q 5x5 8 sym
>> q(1,1:end) = 42
q =
[ 42, 42, 42, 42, 42]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, 42, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!