Filter löschen
Filter löschen

change order of a row vector

3 Ansichten (letzte 30 Tage)
Ismail Güclü
Ismail Güclü am 30 Mai 2020
Kommentiert: Ismail Güclü am 30 Mai 2020
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 Kommentare
madhan ravi
madhan ravi am 30 Mai 2020
Is B a subset of the vector always?
Ismail Güclü
Ismail Güclü am 30 Mai 2020
B shall show you the position from x

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 30 Mai 2020
Bearbeitet: madhan ravi am 30 Mai 2020
ix = setdiff(1:numel(vector), B);
Wanted = [vector(B), vector(ix)]
  2 Kommentare
madhan ravi
madhan ravi am 30 Mai 2020
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ü am 30 Mai 2020
I dont know why but his comment disappeared ...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by