2017-04-08 66 views
1

我创建了一个3x3矩阵。索引操作最初运行良好。在Matlab/Octave中,如何对转置矩阵进行索引?

>> K=rand(3) 

K = 

    0.8147 0.9134 0.2785 
    0.9058 0.6324 0.5469 
    0.1270 0.0975 0.9575 

>> K(:,1) 

ans = 

    0.8147 
    0.9058 
    0.1270 

但是,如果我做转置矩阵的索引操作,MATLAB抛出一个错误:

>> K'(:,1) 
K'(:,1) 
    ↑ 
Error: Unbalanced or unexpected parenthesis or bracket. 
>> (K')(:,1) 
(K')(:,1) 
    ↑ 
Error: Unbalanced or unexpected parenthesis or bracket. 

有没有人有这个想法?

回答

4

这样来做:

K(1,:).' 
% note the dot above (.' - means transpose) 

% however if you want Hermitian then do this 
K(1,:)' 
% (just ' - means Hermitian) 

% well if K is real then it does not matter 
+0

工作,你有我的点给予好评:-) –

2

简单的答案是,这种语法是不允许的(在Matlab中,实际上它是在Octave中,因为另一个答案指出)。你可以做,虽然下面的结果相同

K(1,:)' 

或者

K = K'; 
K(:,1) 

这不会BR太贵作为MATLAB只是翻转指数内部做转置。像其他回答者状态,使用.'复杂的数据或只是作为一个良好的习惯(为什么MathWorks公司吗?为什么?)

4

在八度,你可以真正做到这一点。

注:这并不在MATLAB

K = 

    0.814700 0.913400 0.278500 
    0.905800 0.632400 0.546900 
    0.127000 0.097500 0.957500 

>> (K.')(:,1) 
ans = 

    0.81470 
    0.91340 
    0.27850