I was curious if I could use a "while" loop to change a value inside a matrix to create a series of matrices. I created an array for theta which is 1x37. I was thinking maybe creating a while loop that could take one index at a time and produce a new matrix. Any help is appreciated, thank you.
theta = [-90:5:90]
m = sind(theta);
n = cosd(theta);

2 件のコメント

Rik
Rik 2021 年 2 月 23 日
This is an example of the XY problem. You should not presume a while loop is the solution without a clear description of the problem. You haven't described what you want to do with sufficient detail for someone to be able to give an answer.
andrew krugle
andrew krugle 2021 年 2 月 24 日
Sorry for being unclear, my code is below, what I want to do is create an array of values for theta, from 90 to -90 and would like to plug them into my matrix with my variables m and n which are the function of changing theta. So in the end I would have created 37 new 6x6 matrices.
theta = [-90:5:90]
m = sind(theta);
n = cosd(theta);
T = [m^2 n^2 0 0 0 2*m*n;
n^2 m^2 0 0 0 -2*m*n;
0 0 1 0 0 0;
0 0 0 m -n 0;
0 0 0 n m 0;
-m*n m*n 0 0 0 m^2-n^2]

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 24 日

0 投票

theta = [-90:5:90]
M = sind(theta);
N = cosd(theta);
T = arrayfun(@(m,n)[m^2 n^2 0 0 0 2*m*n;
n^2 m^2 0 0 0 -2*m*n;
0 0 1 0 0 0;
0 0 0 m -n 0;
0 0 0 n m 0;
-m*n m*n 0 0 0 m^2-n^2], M, N, 'uniform', 0);

3 件のコメント

andrew krugle
andrew krugle 2021 年 2 月 24 日
Walter thank you very much!! Exactly what I needed. I saw that it created T with 37 6x6 matrices. Out of curiousity since I've never done matrices within an array and pulling values out, I saw that it created T{1,2},T{1,2} T{1,3}...T{1,37}. If I wanted to pull the first column out of T{1,2} could I create a new vairable such as
C1 = T{1,2}(:,2)
Walter Roberson
Walter Roberson 2021 年 2 月 24 日
C1 = T{1,2}(:,1)
for first column ;-)
col1 = celfun(@(C) C(:,1), T, 'uniform', 0)
to get all of the column 1. You could then proceed to
col1mat = horzcat(col1{:});
to get a 6 x 37 matrix of column 1's
andrew krugle
andrew krugle 2021 年 2 月 24 日
You're amazing, Thank you so much

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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