How to assign a symbolic variable to a location inside a matrix?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chris Verhoeven
el 13 de En. de 2020
Comentada: Chris Verhoeven
el 13 de En. de 2020
I have simplified the problem a little bit.
syms A
x = [A,0;0,0] %this works
y = zeros(2)
y(1,1) = A %THIS DOESNT WORK. WHY NOT?
Since i'm using this in a large function i really need to be able to assign symbolic variable to a matrix using it's row and column number. Please help.
0 comentarios
Respuesta aceptada
Steven Lord
el 13 de En. de 2020
In your expression y(1, 1) = A the expression on the left of the equals sign refers to a double array while the expression on the right is a sym array. In order to perform that assignment MATLAB tries to convert the sym array A into a double value. It can't (what's the numeric value of the symbolic variable A?) so it throws an error.
You could either give the variable A a numeric value, so that MATLAB can convert that value into a double to perform the assignment, or you can create y initially as a sym array so assigning the sym array A into a piece of that sym array requires no conversion.
A = sym(4);
y = zeros(2);
y(1, 1) = A % Note that y remains a double array
syms B
y2 = sym(zeros(2)); % or zeros(2, 'sym')
y2(1, 1) = B % No conversion necessary
Más respuestas (0)
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!