Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
produce N number of matrices through a loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/221425/1.jpeg)
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 commentaire
Geoff Hayes
le 30 Mai 2019
See https://www.mathworks.com/matlabcentral/answers/464248-produce-matrices-through-for-loop for same question.
Réponses (0)
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!