change order of a row vector
3 次查看(过去 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
采纳的回答
madhan ravi
2020-5-30
编辑:madhan ravi
2020-5-30
ix = setdiff(1:numel(vector), B);
Wanted = [vector(B), vector(ix)]
2 个评论
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!