Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Adam Danz
Adam Danz le 16 Déc 2019
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 commentaires
Adam Danz
Adam Danz le 18 Déc 2019
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 le 18 Déc 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by