Info
This question is closed. Reopen it to edit or answer.
produce N number of matrices through a loop
1 view (last 30 days)
Show older comments
Hello people! I want to produce N number of matrices while k=1:N and I want the result in a way like h(k). I mean h(1),h(2) etc which are matrices that depend on k. I mean creating them through a for loop. I tried the following code but it failed to produce N matrices and it just gave one matrix. I want to use this code in another code in a for loop and assume N=5 and k=1:N I want to produce five matrices named h(k) to Place them in the optimization FORMULA I mean when k is 1 it Places h(1) in FORMULA etc. I've attached picture of form of h(k)
clc;
clear;
close all;
%%
hx = [-1/sqrt(5);-2/sqrt(5)];
hu = [0;0];
N = 5;
Ek1 = zeros(N+1,1);
Ek2 = ones(N+1,1);
Ek3 = ones(N,1);
Ek4 = zeros(N,1);
h = zeros(22,N);
for k=1:N
if k==1
h(:,k) = [kron(Ek2,hx);kron(Ek3,hu)];
else
h(:,k) = [kron(Ek1,hx);kron(Ek4,hu)];
end
end
1 Comment
Geoff Hayes
on 30 May 2019
See https://www.mathworks.com/matlabcentral/answers/464248-produce-matrices-through-for-loop for same question.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!