implement the A matrix using for loop

1 回表示 (過去 30 日間)
Chiu tik hong
Chiu tik hong 2021 年 4 月 9 日
編集済み: David Hill 2021 年 4 月 9 日
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 件のコメント
David Fletcher
David Fletcher 2021 年 4 月 9 日
So, what have you tried? I assume that you can see the pattern relating the input to the output?

サインインしてコメントする。

採用された回答

David Hill
David Hill 2021 年 4 月 9 日
編集済み: David Hill 2021 年 4 月 9 日
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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by