How to shorten this code efficiently? (cell array multiple assignation with symbolic variables)
显示 更早的评论
Hi,
I'm working on a code, and a shorter way to do the following will be more than useful.
syms x y;
W=cell(5,5,n); % n is quite a large number, at least 100 or 200
A=[1 0; 0 0]; B=[0 1; 0 0]; C=[0 0; 1 0]; D=[0 0; 0 1]; E=[0 0; 0 0];
x=A; y=A; W(1,1,:)={x y x*x x*y ...} % around 200-300 expressions at least
x=A; y=B; W(1,2,:)={x y x*x x*y ...}
% ... and this continues for all possible combinations of {A,B,C,D,E}
The code follows by using the newly created W cell array. Problem is, that if I want to change the {x y x*x x*y ...} part, I need to rewrite the whole part, therefore if there would be a way to define these in the beginning with some variable, I's need to change only one row.
The second problem is, that I need too many rows to cover all possible combinations of {A,B,C,D,E} with x and y.
Is there a more efficient method to assign these elements to the cell array W? :)
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!