MATLAB: Changing the dimension representation

cell arraysdigital image processing

I have 8 face images (2 diff people with 4 diff expressions each). To arrange the data as multidimensional array, first i put 'people' in rows and 'expressions' in columns using the following code (p=people, e=expressions):
j=2;
k=4;
mydata = cell(j,k);
for p = 1:j
for e = 1:k
fname = sprintf('%d%02d.txt' , p, e);
fid = fopen(fname);
Next,if i want to change the 'expressions' be in the rows and 'people' in column, how can i do that without changing the file names. I name the image as 101-104 for the first person with four expressions and 201-204 for the second person.I know that first i will change :
j=4;
k=2;
mydata = cell(j,k);
for e = 1:j
for p = 1:k
fname = sprintf('%d%02d.txt' , e, p);
fid = fopen(fname);
but i don't know how to change the '%d%02d.txt'. Anyone have an idea? Or does the changes in dimension representation can be done in only one file? I mean without creating another m file.

Best Answer

First, a piece of advice, use variable names that have meaning, preferably full words. It's impossible to tell from their name alone what j, k, e, p represent. personcount, expressioncount, person, expression, are much clearer. Even mydata is not very good, it doesn't say what kind of data it holds. I assume images of people expression, so imgexpression would be better.
Second, there is nothing in the snippet you've posted that depends on the order of the dimension. If you swap the order of the dimensions, the only two lines that need to change are the array declaration and the assignment to it (which you haven't shown). Certainly not the order of the loops, nor the sprintf call. So:
expressioncount = 4;
personcount = 2;
imgexpression = cell(personcount, expressioncount);
%or if you swap:
%imgexpression = cell(expressioncount, peoplecount);
%the loop order does not matter one bit
for person = 1:personcount
for expression = 1:expressioncount
fname = sprintf('%d%02d.txt', person, expression); %according to your description this is what you should be using
fid = fopen(fname);
%... some code
%at some point you need to do the assignment
imgexpression{person, expression} = ...
%if you swap:
%imgexpression{expression, person} = ...
end
end