How can I loop into a matrix?

1 回表示 (過去 30 日間)
saheed
saheed 2014 年 3 月 7 日
コメント済み: saheed 2014 年 3 月 8 日
I have six values of E and v which are entries of Matrix s of the structure; s=[1/E -v/E 0; v/E 1/E 0; 0 0 2*(1+v)/E]
the six matrices of s formed are the entry into the matrix S; S=[s(1) s(2) s(3) s(4) s(5) s(6)]
How can I loop the values of E and v into the matrix s?
  2 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 7 日
Are E and V row matrices or column matrices? What do you think the size of little should be? And what about big S? Can you give a numerical example?
saheed
saheed 2014 年 3 月 7 日
E and v are coulmn matrices and the size of matrix s is 3 by 3 while size of matrix S is 3 by 18 since we have 6 s matrices in the column space of matrix S. for example,
s(i)=[1/E(i) -v(i)/E(i) 0; v(i)/E(i) 1/E(i) 0; 0 0 2*(1+v(i))/E(i)]
where i=1,2,..,6 for each value of E and v

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

採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 7 日
I assume you are trying to do something like
for ii = 1:6
S{ii} = [1 -v(ii) 0; v(ii) 1 0; 0 0 2*(1+v(ii))]/E(ii);
end
Note that S is a cell array, so your first matrix (your s(1)) would be accessed as S{1}.
  3 件のコメント
Mischa Kim
Mischa Kim 2014 年 3 月 7 日
Yep, either way would work. My thinking was that Saheed wanted to access the inidividual matrix elements of S = [s(1) s(2) s(3) s(4) s(5) s(6)] with something that resembled that format.
saheed
saheed 2014 年 3 月 8 日
Thanks Patrick and Mischa. Patrick code works fine and suit my need.

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

その他の回答 (1 件)

Patrik Ek
Patrik Ek 2014 年 3 月 7 日
編集済み: Patrik Ek 2014 年 3 月 7 日
I think that you need to loop here, since Matlab do normally not implement any operations that you reuqests. I mean
[vector, 0; 0, vector]
gets the size 2 x length(vector)+1
try something like
s = [];
for k = 1:length(E)
s_temp= [1/E(k) -v(k)/E(k) 0; v(k)/E(k) 1/E(k) 0; 0 0 2*(1+v(k))/E(k)];
s = [s,s_temp];
end
I may have some syntax errors since the code is not tested, but I guess it should work. Of course you can also preallocate vectors and so as well to speed up the code, if that is necessary.
Good luck!

カテゴリ

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