Matrix dimensions to create for loop?

6 ビュー (過去 30 日間)
jack star
jack star 2016 年 5 月 16 日
回答済み: jack star 2016 年 5 月 16 日
Hi all. I have rr(6x200) matrix. I want to find Rc and V matrixes for each 200 column, I showed below for one column:
Rc=toeplitz(rr(1:6)); %Rc(6x6)
V=Rc\eye(6,1); %V(6x1)
In the end, I need V matrix (6x200) but because of Rc is (6x6) matrix I could not create for loop.
  1 件のコメント
Jos (10584)
Jos (10584) 2016 年 5 月 16 日
You meant R= toeplitz(rr(:,k)), where k runs from 1 to 200?

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2016 年 5 月 16 日
編集済み: Guillaume 2016 年 5 月 16 日
I'm not sure why you can't use a loop:
V = zeros(size(rr));
denum = eye(size(rr, 1), 1); %so it's not recreated 200 times in the loop
for col = 1 : size(rr, 2)
Rc = toeplitz(rr(:, col));
V(:, col) = Rc \ denum;
end
Alternatively:
denum = eye(size(rr, 1), 1);
V = cell2mat(cellfun(@(col) toeplitz(col)\denum, num2cell(rr, 1), 'UniformOutput', false))
The loop is likely to be marginally faster.

その他の回答 (2 件)

Jos (10584)
Jos (10584) 2016 年 5 月 16 日
You can use a for-loop:
rr = rand(6,200) ;
[nr,nc] = size(rr) ;
X = eye(nr,1) ; % take it out of the loop
V = zeros(nr,nc) ; % pre-allocation
for k=1:nc % loop over columns
Rc = toeplitz(rr(:,k)) ;
V(:,k) = Rc \ X ;
end

jack star
jack star 2016 年 5 月 16 日
Both works fine, thanks a lot.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by