How to separate an array into 3
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi I am trying to divide one array into 3 arrays
let's say A = [11 22 33 44 55 66 77 88 99]
I want to divide A like this:
B = [11 33 55 77]
C = [22 44 66 88]
D = [99]
This is just an example...Could you come up some idea for this?
0 Commenti
Risposte (2)
Stephen23
il 29 Mag 2020
>> A = [11,22,33,44,55,66,77,88,99];
>> B = A(1:2:end-1)
B = 11 33 55 77
>> C = A(2:2:end-1)
C = 22 44 66 88
>> D = A(end)
D = 99
0 Commenti
Brent Kostich
il 28 Mag 2020
A simple way is by indexing, like so:
A = [11 22 33 44 55 66 77 88 99];
B = A([1, 3, 5, 7]);
C = A([2, 4, 6, 8]);
D = A(9);
If you are looking for a more general solution than explicit indexing, then you will have to provide more parameters for your problem.
2 Commenti
Brent Kostich
il 29 Mag 2020
If you wanted to filter by even and odd, then you should have specified that in your question. That operation is not difficult though, see Stephen Cobeldick's answer.
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!