필터 지우기
필터 지우기

change order of a row vector

조회 수: 3 (최근 30일)
Ismail Güclü
Ismail Güclü 2020년 5월 30일
댓글: Ismail Güclü 2020년 5월 30일
I am trying to change the order of a vector [ 1 2 3 4 5 6] into [ 3 4 5 1 2 6] while using a determinative vector B=[ 3 4 5],
but when I run the code I get a vector [3 4 5 2 1 6];
x == num
for i = 1:length(B)
if isequal(B(i),num(i)) == 0
tmp = num(i);
num(i) = num(B(i));
num(B(i)) = tmp;
end
end
  댓글 수: 2
madhan ravi
madhan ravi 2020년 5월 30일
Is B a subset of the vector always?
Ismail Güclü
Ismail Güclü 2020년 5월 30일
B shall show you the position from x

댓글을 달려면 로그인하십시오.

채택된 답변

madhan ravi
madhan ravi 2020년 5월 30일
편집: madhan ravi 2020년 5월 30일
ix = setdiff(1:numel(vector), B);
Wanted = [vector(B), vector(ix)]
  댓글 수: 2
madhan ravi
madhan ravi 2020년 5월 30일
Wow just realised sir Walter answered it after reading the activity feed. I acknowledged the generosity sir Walter. Thank you!
Ismail Güclü
Ismail Güclü 2020년 5월 30일
I dont know why but his comment disappeared ...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by