Saving matrix data from nested for loop
Show older comments
I have a 18624*3 matrix called 'vertices2' that I wish to break up into separate matrices of 24*3 e.g. rows 1-24, 25-48 and so on. I have the following code which loops through my matrix to (almost) do what I want but it has two problems:
[x,y] = size(vertices2);
for i = 1:24:x
for j = 1:3:y
vertices3(i,j) = vertices2(i:(i+23), j:(j+2));
end
end
As it stands I get the following error... 'Assignment has more non-singleton rhs dimensions than non-singleton subscripts'. This isn't an error message I'm used to getting from using for loops.
If I remove the (i,j) then the code works but as you'd expect, the loop only saves that last iteration of the loop e.g. data from rows 18601-18624, which is of no use to me!
I've tried a number of variations of the code to get it to run but I'm hitting a brick wall and was hoping someone could help! Maybe the step I'm missing is to save each iteration as a new matrix before the loop moves onto the next??
Thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!