It mainly solves the number in a graph and how to flexibly change the number to achieve the goal of changing the number.
The most important thing is to use the cellular array. For example, Im is a 16*20 cellular array, and the number of each cellular is 16*16*3. How can we arrange 768 of each cell in a row in order?
Im is transformed into a matrix of 320*728. Each row represents a cell.
Before getting started with the cellular array, I could naturally think of two for loops:
A = [];
T = 1;
For J = 1:20
For I = 1:16
A (t, :) = Im {I, j }(:);
T = t + 1;
End
End
In this way, a is required.
Although the Code of the For Loop is simple and saves your own troubles, it is not worth it because it gives the difficulties to the computer and the time is used to change the troubles!
If you do not need a for loop, you can use the cellular array:
Im_1 = CAT (4, Im {:});
Im_2 = reshape (im_1, [16*16*3, 16*20]) ';
In this way, im_2 is required, that is, it is equal to the phase.
I always think that through various conversions, errors will occur if you don't have to worry about it. For example, if you write
Im_1 = CAT (4, Im {:});
Im_22 = reshape (im_1, [16*20, 16*16*3]);
In this way, im_22 is the same as im_1 through whos, but in fact, the returned value of isequal (im_1, im_22) is 0.
So be careful. Otherwise, you will not even know what is wrong.
Finally, clock is used to test the running time of the above two methods:
T1 = clock;
A = [];
T = 1;
For J = 1:20
For I = 1:16
A (t, :) = Im {I, j }(:);
T = t + 1;
End
End
T2 = clock;
Waiting = t2-t1;
The displayed result is waiting1 = 0.056.
Using the cellular array:
T1 = clock;
Im_1 = CAT (4, Im {:});
Im_2 = reshape (im_1, [16*16*3, 16*20]) ';
T2 = clock;
Waiting2 = t2-t1;
In this case, waiting2 is 0.004;
Compared with waiting1 and waiting2, you can easily find a 10-fold difference.