Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It sounds like you're trying to figure out the best way to collect your various <strong>8-by-8</strong> matrices into a single variable. There are a few ways you can do this (with the first option being the one I would choose for your case):</p> <ul> <li><h2>Concatenating data into a 3-D matrix:</h2> <p>You can use the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/cat.html" rel="nofollow noreferrer">CAT</a> function to stack matrices of the same size along a given dimension. For example, if you have your 4 <strong>8-by-8</strong> luminance matrices in the variables <code>L1</code>, <code>L2</code>, <code>L3</code>, and <code>L4</code>, the following will concatenate them into an <strong>8-by-8-by-4</strong> matrix:</p> <pre><code>luminance = cat(3,L1,L2,L3,L4); </code></pre> <p>You could also add the additional <code>Cb</code> and <code>Cr</code> matrices to create an <strong>8-by-8-by-6</strong> matrix:</p> <pre><code>macroBlock = cat(3,L1,L2,L3,L4,Cb,Cr); %# OR... macroBlock = cat(3,luminance,Cb,Cr); %# Using luminance variable from above </code></pre> <p>You can then index <code>macroBlock</code> in the following way to access whatever <strong>8-by-8</strong> matrices you need:</p> <pre><code>L2 = macroBlock(:,:,2); %# Get the second luminance matrix Cb = macroBlock(:,:,5); %# Get the Cb matrix </code></pre></li> <li><h2>Storing data in a cell array:</h2> <p>Since all of your matrices are the same size, the above concatenation option is probably best. However, another option (which is especially useful if you want to store data of varying size, type, or dimension) is to use <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04bw6-98.html" rel="nofollow noreferrer">cell arrays</a>. The following creates a <strong>1-by-6</strong> cell array containing the above matrices:</p> <pre><code>macroBlock = {L1 L2 L3 L4 Cb Cr}; </code></pre> <p>You can then index <code>macroBlock</code> in the following way to access whatever <strong>8-by-8</strong> matrices you need:</p> <pre><code>L2 = macroBlock{2}; %# Get the second luminance matrix Cb = macroBlock{5}; %# Get the Cb matrix </code></pre></li> <li><h2>Storing data in a structure:</h2> <p>Another option is to use a <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/struct.html" rel="nofollow noreferrer">structure</a> to store your <strong>8-by-8</strong> matrices. A structure has the benefit that you can access data <em>by field name</em> as opposed to having to remember an index value. Here's how you would initialize a structure:</p> <pre><code>macroBlock = struct('L1',L1,'L2',L2,'L3',L3,'L4',L4,'Cb',Cb,'Cr',Cr); %# OR... macroBlock = struct(); macroBlock.L1 = L1; macroBlock.L2 = L2; macroBlock.L3 = L3; macroBlock.L4 = L4; macroBlock.Cb = Cb; macroBlock.Cr = Cr; </code></pre> <p>The two syntaxes above create a structure with field names <code>'L1'</code>, <code>'L2'</code>, <code>'L3'</code>, <code>'L4'</code>, <code>'Cb'</code>, and <code>'Cr'</code>. You can then index <code>macroBlock</code> in the following way to access whatever <strong>8-by-8</strong> matrices you need:</p> <pre><code>L2 = macroBlock.L2; %# Get the second luminance matrix Cb = macroBlock.Cb; %# Get the Cb matrix </code></pre></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload