How do I combine 2 arrays into one but in a specific order.
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jaya
2021-7-7
编辑:Jaya
2021-7-7
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.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!