MATLAB是特定于行还是特定于列? [英] Is MATLAB row specific or column major?

查看:62
本文介绍了MATLAB是特定于行还是特定于列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中,我们可以对矩阵的行和列进行操作.行主要"指的是什么?或专栏专业"?

In MATLAB, we can operate on both rows and columns of a matrix. What does it exactly mean by "row major" or "column major"?

推荐答案

重要的是要了解MATLAB将数据存储在

It is important to understand that MATLAB stores data in column-major order, so you know what happens when you apply the colon operator without any commas:

>> M = magic(3)
M =
     8     1     6
     3     5     7
     4     9     2
>> M(:)
ans =
     8
     3
     4
     1
     5
     9
     6
     7
     2

我倾向于认为"MATLAB先跌后跌".这使得 reshape permute 数组变得很容易,而不会扰乱数据.为了掌握线性索引(例如 M(4)).

I tend to think "MATLAB goes down, then across". This makes it easy to reshape and permute arrays without scrambling your data. It's also necessary in order to grasp linear indexing (e.g. M(4)).

例如,从生成数组的某些表达式中获取列向量内联的一种常见方法是:

For example, a common way to obtain a column vector inline from some expression that generates an array is:

reshape(<array expression>,[],1)

(:)一样,它会将所有列彼此堆叠成单个列向量,以获取任何更高维度的所有数据.但是这个漂亮的语法技巧可以让您避免额外的代码行.

As with (:) this stacks all the columns on top of each other into single column vector, for all data in any higher dimensions. But this nifty syntactic trick lets you avoid an extra line of code.

这篇关于MATLAB是特定于行还是特定于列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆