Info

此问题已关闭。 请重新打开它进行编辑或回答。

produce N number of matrices through a loop

2 次查看(过去 30 天)
Ali Esmaeilpour
Ali Esmaeilpour 2019-5-28
关闭: Stephen23 2019-5-30
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)
1.jpg
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

回答(0 个)

此问题已关闭。

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by