I'm working on a project where i need to exchange multidimensional data
between C/C++ (row-major) and matlab (column-major). I understand the
difference between those two mappings to linear memory.
Suppose I need an S1 x S2 x ... x Sn dimensional array A. I can have the
same layout in memory by reversing the dimensions:
A[S1]...[Sn] == A(Sn,...,S1)
where I used the C/C++ notation for row-major and the matlab notation
for column-major (and forget about the issue of zero-based vs one-based
access). So far no problem.
But when I start "naming" the dimensions (with row and column), this
reversing does not seem to hold anymore. Let my explain that by
progressively adding dimensions in both cases: (r=row,c=column,p=plane)
C/C++ (row-major):
1D: [c] --> row vector
2D: [r][c]
3D: [p][r][c]
Matlab (column-major):
1D: (r) --> column vector
2D: (r,c)
3D: (r,c,p)
As you can see in 3D, the order of the dimensions is not what I
expected. r and c are not in reverse order. And the more I start
reasoning about it, the more I get confused. What am I missing?