Accesing data in a three dimensional matrix using a for loop
Show older comments
Hi, I want to create a for loop to go through each of the pages (20) of a matrix 400x600x20 (called polygons). The matrices 400x600 are binary matrices with ones(1) and zeros(0), with different polygons in each of the 20 pages. I have an original matrix (called main01) of 400x600 from where I want to use the data to copy the ones(1) and zeros(0) and locate it in the polygons in each of the 20 pages of the other variable. So I try this creating a variable of only the first page of the matrix polygons:
polygon1(polygon1==1)=main01(polygon1==1);
And it works very well. However, when I set this into a for loop it doesn't give me the zeros and ones of the main01 matrix, it just return the same matrix as polygons.
count=20;
for u=1:1:count;
if polygons(:,:,u)==1
polygons=main01(polygons(:,:,u)==1;
end
end
I will appreciate some help with this for loop.
Thank you. Martha
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays 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!