フィルターのクリア

How to input and operate matrices using loop?

1 回表示 (過去 30 日間)
Umair Khan
Umair Khan 2016 年 7 月 1 日
回答済み: John 2016 年 7 月 7 日
I have 1000 matrices with names C1, C2 ...... C1000. I want to input these matrices, using loop, into my function and operate them in this way:
D1 = 0.5*sum(diag((C1)-(C2)*(inv(C2)-inv(C1))))
D2 = 0.5*sum(diag((C2)-(C3)*(inv(C3)-inv(C2))))
.
.
.
Dn = 0.5*sum(diag((Cn)-(Cn+1)*(inv(Cn+1)-inv(Cn))))
Then i want to store the values of D in a vector named Distance.
Distance=[D1,D2,....,Dn]
Can anyone help me?
  5 件のコメント
Umair Khan
Umair Khan 2016 年 7 月 7 日
@Stephen Cobeldick: The solution of David works fine.
In your suggested page, i found that dynamically creation of variables is bad and we should use, for example, cell arrays. In david's solution we used cell arrays. Means its fine???
Stephen23
Stephen23 2016 年 7 月 7 日
編集済み: Stephen23 2016 年 7 月 7 日
@Umair Khan: David Miller's solution is good (it should really have been submitted as an answer).
Note that David actually uses numeric array, not a cell array as you state.

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

回答 (1 件)

John
John 2016 年 7 月 7 日
Concatenate all of your matrices to create a 3D array C and index the 3rd dimension using your loop variable i.e. C(:,:,1) would index the matrix C1

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by