implement the A matrix using for loop
조회 수: 1 (최근 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
2021년 4월 9일
So, what have you tried? I assume that you can see the pattern relating the input to the output?
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!