필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
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.

채택된 답변

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by