For loops question Help

Can someone please explain the steps to this problem for me?
What is the variable y as the result of the given Matlab code fragment?
index = 1;
x = [3 -1 2 4 6];
test = [2 5 1 3];
for var = test
y(index) = x(var);
index = index+1; end y = -1 6 3 2

 采纳的回答

Matt J
Matt J 2013-2-26
编辑:Matt J 2013-2-26
y is just a re-ordering of the elements of x in the order given by "test". You could have done this in one line as follows
>> y=x(test)
y =
-1 6 3 2

更多回答(0 个)

类别

帮助中心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!

Translated by