implement the A matrix using for loop

6 vues (au cours des 30 derniers jours)
Chiu tik hong
Chiu tik hong le 9 Avr 2021
Modifié(e) : David Hill le 9 Avr 2021
Given two 1D-vectors:
x = [286; 206; 191; 487; 510];
y = [93; 523; 333; 494; 221];
how to implement the A matrix using for loop and using the 2 vetcors?
matrix A should be the same as below:
A(:,1)=[286;0;206;0;191;0;487;0;510;0];
A(:,2)=[93;0;523;0;333;0;494;0;221;0];
A(:,3)=[1;0;1;0;1;0;1;0;1;0];
A(:,4)=[0;286;0;206;0;191;0;487;0;510];
A(:,5)=[0;93;0;523;0;333;0;494;0;221];
A(:,6)=[0;1;0;1;0;1;0;1;0;1];
  1 commentaire
David Fletcher
David Fletcher le 9 Avr 2021
So, what have you tried? I assume that you can see the pattern relating the input to the output?

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 9 Avr 2021
Modifié(e) : David Hill le 9 Avr 2021
Why do you need a for-loop? Looks like you have the idea.
A=zeros(2*length(x),6);
A(1:2:end,1)=x;
A(1:2:end,2)=y;
A(1:2:end,3)=1;
A(2:2:end,4)=x;
A(2:2:end,5)=y;
A(2:2:end,6)=1;
You could
A=zeros(2*length(x),6);
X=[ones(length(x),1),x,y];
for k=1:6
if k<=3
A(1:2:end,k)=X(:,mod(k,3)+1);
else
A(2:2:end,k)=X(:,mod(k,3)+1);
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by