I was trying to use for loop to assign some matrix to some variables. But I could not realize it. I probably know where is my mistake, but I don't know whether there is a way to overcome it
N = 10;
for i = 1:1:N
P(i) = [x(i)^2 x(i)*y(i);
x(i)*y(i) y(i)^2];
end
K = blkdiag(P);
I want to assign a matrix to P(i), then use those P(i) to create a block diagonal matrix. But it seems that I can't do this. Is there any other methods to create such block diagonal matrix?
You can use a cell array for this:
for i = 1:10
P{i} = [x(i)^2 x(i)*y(i);
x(i)*y(i) y(i)^2];
end
K = blkdiag(P{:});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With