# How to arrange a column vector into two columns?

8 views (last 30 days)
Heirleking on 4 Feb 2022
Edited: Heirleking on 4 Feb 2022
So, I have this vector and I need to arrange it as loops. Each value for each loop should start as the next integer from the previous ending loop x= [128 147 166 181 195 216 236 255]
It should look something like this x= [128 147; 148 166; 167 181; 182 195; 196 216; 217 236; 237 255]
I cannot do it manually, since I have to arrange several vectors that will not have the same length as this one. I tried using nested for loops but wasn't successful
Heirleking on 4 Feb 2022
You are right, I corrected the mistake

Stephen23 on 4 Feb 2022
Edited: Stephen23 on 4 Feb 2022
Assuming that the missing 236/237 row is a mistake:
x = [128,147,166,181,195,216,236,255]
x = 1×8
128 147 166 181 195 216 236 255
m = [x(1),1+x(2:end-1);x(2:end)].'
m = 7×2
128 147 148 166 167 181 182 195 196 216 217 236 237 255

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!