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

查看:22
本文介绍了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 将数据存储在 column-major 顺序,所以你知道当你应用没有任何逗号的 colon 运算符时会发生什么:

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 下降,然后跨越".这使得reshapepermute 数组变得容易,而不会打乱您的数据.为了掌握线性索引(例如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天全站免登陆