How do I combine 2 arrays into one but in a specific order.
20 views (last 30 days)
Show older comments
I need to combine 2 arrays: one contains even values and one containes odd values. How do I go about doing this? I attempted to do a while loop and place the values in but i cant seem to set it up right. Any help would be great :)
temp_even = [9.2 9.0 6.8 5.9 7.2 9.2 10.9 10.6 10.3 8.2 8.8 7.5];
temp_odd = [9.6 7.7 6.0 4.3 8.9 10.2 10.6 10.7 8.6 8.0 7.1 7.5];
2 Comments
Jaya
on 7 Jul 2021
Edited: Jaya
on 7 Jul 2021
Do you mean just combining them in a simple manner? Then you can use
res= horzcat(temp_even,temp_odd)
and then just use sort using
sort(res,'ascend')
%or this sort(res, 'descend')
Or is it something else you want to do? If you want to place one even number one odd number as you traverse the array then you may have to use loop, check each element and place one by one in a third array. This is what I would do but I don't know if there is any smart way to do it.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical 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!