- Column major order (like C), adjacent elements are adjacent columns. This corresponds to the convention for graphing, where the first coordinate of an (x,y) pair is the horizontal distance and the second coordinate is the vertical distance. Variable(3,5) corresponding to Variable indexed at x = 3 and y = 5 is a natural match for this arrangement
- Row major order (like MATLAB and Fortran), adjacent elements are adjacent columns. This corresponds to the convention for tables of data such as the old log tables like those shown at http://www.sliderules.info/a-to-z/log-4f.gif where you go to a particular row as the less refined coordinate, and then go across the columns for the more detailed answer. You do not say "Go to column 5, line 7", you say "Go to line 7, column 5"
What does [3, Inf] represents?
5 次查看(过去 30 天)
显示 更早的评论
sizeA = [3 Inf];
Does it mean 3 rows and infinite colums?
In the workspace it shows: sizeA = [3, Inf].
How to interpret it?
0 个评论
采纳的回答
Walter Roberson
2020-12-3
In addition to what the others say: that kind of variable would tend to be used as the size parameter for reading data, such as fread() or fscanf(), both of which literally use the name sizeA in the documentation
In both cases, using [3 inf] as in the sizeA position of fread() or fscanf() would mean that you want to read the data into 3 rows and as many columns as there is available data.
Also (and this is important), the data that is read in is assigned "down" the rows fastest, so the first data item read in would go to (1,1), the second data item read in would go to (2,1), the third to (3,1), the fourth to (1,2), the fifth to (2,2), the sixth to (3,2) and so on. It would be common to be reading from a text file that contained three columns and an unknown number of rows, but you would specify [3 inf] as the size, and the data would be stored down rows instead of across columns. If you fscanf(fid, '%f %f %f', [3 inf]) then the second item of the first row does not get stored to the second column of the first row of the output variable: it gets stored as the second row of the first column of the output.
So, when you are reading a text file that has columns of numbers, the data is read following across rows, but stored down columns. You would typically follow the fscanf() by a transpose to get the data back in the original order
data = fscanf(fid, '%f %f %f', [3 inf]).' ; %notice the transpose
and that transposed data would have the data stored in the same order it appears in the file.
This is a notable difference between computer languages, whether adjacent values stored in memory are adjacent rows in the same column, or adjacent columns in the same row. MATLAB uses "row major order", as does Fortran. C and C++ use "column major order", which is probably more common in computer languages these days.
"row major" compared to "column major" order is not right or wrong for a computer language to use, just a difference. There are two opposing ways that "Western Civilization" humans deal with data, and we tend to mentally flip between them without noticing and then get confused when we have to deal with the consequences either way.
These two conventions are incompatible, so no matter which one the computer language chooses, it will feel "unnatural" when dealing with data that follows the other convention.
更多回答(1 个)
David Hill
2020-12-3
That is an array/vector with two elements 3 and Inf named sizeA. Workspace would show size as 1x2.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!