I have an array:
step1 = [0,0;
0,1;
1,1;
2,3;
3,4;
3,5;
3,6;
3,7;
4,7;
5,7;
6,7;
6,6;
6,5;
6,4;
6,3;
6,2;
5,1];
I want to step through this array and create new arrays for the row and column that increment by 0.1 from one row to another. This is what I did:
z=1;
u=length(step1);
step_b4X = zeros(u,1);
step_b4Y = zeros(u,1);
while z <= length(step1)
step_b4X = step_presentX;
step_presentX(z,1) = step1(z,1);
step_b4Y = step_presentX;
step_presentY(z,1) = step1(z,2);
pathX = step_b4X:0.1:step_presentX;
pathY = step_b4Y:0.1:step_presentY;
z = z+1;
end
I get zeros.
I want pathX = 0:0.1:0….pathY = 0:0.1:1
next pathX = 0:0.1:1….pathY = 1:0.1:1… and so on
If you do
where
start == end, you’ll get a scalar equal tostart(which is logical).If you want
pathXandpathYto have the same length at each iteration, you’ll have to do this:Now you’ll have the right arrays at each iteration, that you’ll use directly or save in a
cell-array for later. If you want everything in one big array, add this to the end of the loop:and initialize them as empty before the loop, of course.
Alternatively (much cleaner and possibly a bit faster), ditch the whole loop and use
interp1: