implement the A matrix using for loop

5 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by