Finding index in a set
이전 댓글 표시
Hello. I have these two sets.
x1 = [0 , 0, 1, 0]
x2 = [0, 0, 0, 0]
I want to randomly generate one in x2 except the index 3, where the vaule is x1. The output will be look like:
x1 = [0, 0, 1, 0]
x2 = [1, 0, 0, 0] or [0, 1, 0, 0] or [0, 0, 0, 1].
How can I do that?
채택된 답변
추가 답변 (1개)
one approach:
x1 = [0 , 0, 1, 0];
x2 = [0, 0, 0, 0];
% [value I]=find(x1==1);
b=perms(x1);
[row,col,v] = find(b(:,3));
b(row,:)=[];
c=b;
output=unique(c,'rows','stable')
댓글 수: 4
Md. Nazrul Islam Siddique
2022년 12월 17일
편집: Md. Nazrul Islam Siddique
2022년 12월 17일
Md. Nazrul Islam Siddique
2022년 12월 17일
편집: Md. Nazrul Islam Siddique
2022년 12월 17일
I am confused. you can make x2 in sveral ways.
x1 = [0 , 0, 1, 0];
x2=circshift(x1,1,2)
x3=circshift(x1,2,2)
x4=circshift(x1,3,2)
or using a function
x=4;
shiftv=2;
output=binvector(x,shiftv)
function y=binvector(x,shiftv)
y=zeros(1,x);
y(shiftv)=1;
end
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!