how to run a 3x3 matrix through a for loop and save all instances of the [3x3]

5 ビュー (過去 30 日間)
Tommy Pestolesi
Tommy Pestolesi 2019 年 12 月 16 日
コメント済み: Adam Danz 2019 年 12 月 18 日
I have a [3x3] transformation matrix A = [ -sind(omega*t), cosd(omega*t), 0; cosd(omega*t), sind(omega*t) cosd(phi); cosd(omega*t), sind(omega*t), sin(phi)]
omega and phi are constants defined earlier. t is the vaiable that is being looped for. if I have 300 values for t, I would like to output 300 different [3x3] matricies, each one corresponding with a different value of t. for more information t is a value that is being read in from a data sheet.
  2 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 16 日
Is t a row or column vector?
Tommy Pestolesi
Tommy Pestolesi 2019 年 12 月 16 日
column

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

採用された回答

Adam Danz
Adam Danz 2019 年 12 月 16 日
A is a cell array the same size as t where A{n} is the matrix for t(n).
omega = 1;
phi = 1;
t = linspace(0,5,300);
A = arrayfun(@(t)[-sind(omega*t), cosd(omega*t), 0;
cosd(omega*t), sind(omega*t) cosd(phi);
cosd(omega*t), sind(omega*t), sin(phi)],t,'UniformOutput',false);
  11 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 18 日
From your question, "t is the vaiable that is being looped for. if I have 300 values for t".
In reality you have 900 values for t.
If I use these inputs
t = rand(300,3);
A = arrayfun(@(t)[-sind(omega*t), cosd(omega*t), 0;
cosd(omega*t), sind(omega*t) cosd(phi);
cosd(omega*t), sind(omega*t), sin(phi)],t,'UniformOutput',false);
A is a 300x3 cell array. I'm guessing that's not what you want.
It's now unclear how to apply each element of t to the transformation matrix. The current code is processing each single value of t. I suppose you want to input rows of t. Is that correct?
Adam Danz
Adam Danz 2019 年 12 月 18 日
maybe this is what you're looking for
t = rand(300,3);
A = arrayfun(@(i)[-sind(omega*t(i,1)), cosd(omega*t(i,1)), 0;
cosd(omega*t(i,2)), sind(omega*t(i,2)) cosd(phi);
cosd(omega*t(i,3)), sind(omega*t(i,3)), sin(phi)],1:size(t,1),'UniformOutput',false);
or perhaps this
t = rand(300,3);
A = arrayfun(@(i)[-sind(omega*t(i,1)), cosd(omega*t(i,2)), 0;
cosd(omega*t(i,1)), sind(omega*t(i,2)) cosd(phi);
cosd(omega*t(i,1)), sind(omega*t(i,2)), sin(phi)],1:size(t,1),'UniformOutput',false);
But I haven't put too much thought into it, mainly because I gotta run. Think about how the values of t are being fed into the arrayfun and how you want to apply those value to your transformation matrix. I can check back later.

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

その他の回答 (0 件)

カテゴリ

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