Rearraning an Array of variable size

1 view (last 30 days)
Hello Matlab Comm
I am not a coder but since the corona crisis my thesis was transformed into matlab case. I have the following problem:
I have an array of size x (odd or even size, both occur). Lets make it x==20 for this example. My goal is to re-arrange the order of the lines in the array.
e.g. if
x=20
Array=zeros(x,1)
for k=1:x
Array(k,1) = k;
end
We have Array() look smth like
1
2
3
4
5
...
19
20
I want to rearaange Array() so the order becomes
1
20
10
5
15
3
13
7
17
4
14
...
So, always order of Min, Max, and mid. I hope you get what I mean. I think it is sort of a Binary Tree but I really a, stepping in the dark here. Any help is gratly appreciated!
I am happy to answwer any questions and explain in more detail. Thanks in advance for any help!
Kindly
Willi

Accepted Answer

Rhea Chandy
Rhea Chandy on 6 Aug 2020
Hello Wilhelm,
It is my understanding that you are looking to understand how to rearrange an array.
The documentation Reshaping and Rearranging Arrays will help you to understand how to reshape and rearrange arrays in any order. For further information, you can find how to filter the elements of an array by applying conditions to the array, by referring to the documentation Find Array Elements That Meet a Condition.
  1 Comment
Wilhelm Rpprt
Wilhelm Rpprt on 6 Aug 2020
Hi Rhea
Thanks alot for this help. I will look into those

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!