How do I combine 2 arrays into one but in a specific order.
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sergey Popov
el 7 de Jul. de 2021
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 comentarios
Jaya
el 7 de Jul. de 2021
Editada: Jaya
el 7 de Jul. de 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.
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!