I have posted a question on here before regarding the generation of a number sequence. I followed up that question with an answer. However, as I have developed my code more I need to use an equation instead of a lookup table.(adsbygoogle = window.adsbygoogle || []).push({});

Note: I'm using MATLAB

Given a matrix A of size r x c where r >= 3, c >= 3 I need to map the center point of a 3 x 3 raster segment to a point in A. The raster segments go from left to right, top to bottom. For example, if

The location of (2,2) in each raster segment can be found as follows.Code (Text):A = [0 1 1 0 1 0 1 0 1;...

0 0 1 0 0 1 1 0 1;...

1 0 1 1 0 1 0 1 0;...

1 1 1 1 1 1 1 1 1];...

I only need matrix M to find what rM and cM are. Instead of using theCode (Text):%raster binary image matrix into 3x3 segments

M = im2col(FP, [3,3],'sliding');

[ri ci] = size(A);

[rM cM] = size(M);

%Generate table of locations in binary image matrix for center point (2,2) of segment matrices

rownums = repmat([2:ri-1],cM/(ri-2),1);

rownums = rownums(:);

colnums = repmat([2:ci-1]',1,cM/(ci-2));

colnums = colnums(:);

locations = [rownums,colnums]im2col()function, I can use the equations below. cM is the number of total raster segments

I do some matrix operations for each raster segment using a for loopCode (Text):rM = 9;

cM = (ci-2)*(ri-2);

I would like to replace this line of codeCode (Text):n = 1;

k = 1;

for row = 1:ri-2

for col = 1:ci-2

%some operations

if %condition is met

%transform center point location in raster segment

%to corresponding location in matrix A

Iloc(n,:) = locations(k,:);

n = n+1;

end

else %if condition is not met, increment segment counter k and continue

%in for loop to next segment

k = k+1;

continue

end

k = k+1;

end

end

with equations for the row and column location in A instead of looking up in the table for these locations. The reason for this is that if I have a matrix A of size 274 x 234, I would have 63104 raster segments. This means that my location table matrix would be 63104 x 2. This takes up a lot of memory with the other stuff that I am doing. I know it's possible to come up with some equation that's dependent on the value of row, col, and k. It seems that every (ci-2) kth value, the row in A increments by one. For every different row value, the column values go from 2:(ci-1).Code (Text):Iloc(n,:) = locations(k,:);

Question is how do I activate the row increment and column range for every (ci-2) kth value?

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# [Matlab] Transform generated table to equation for for loop usage

Loading...

Similar Threads - Matlab Transform generated | Date |
---|---|

Matlab Plotting Coordinate Transformations in Matlab | Feb 12, 2018 |

Matlab Split-step Fourier method | Apr 4, 2016 |

Matlab Matlab syntax for 2-d fourier transform | Mar 21, 2016 |

Matlab Fourier transform of a 2D shape | Mar 21, 2016 |

Using the Fourier Transform on Partitioned Images | Dec 3, 2015 |

**Physics Forums - The Fusion of Science and Community**