2017-04-08 151 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