while loop for changing vairable
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
andrew krugle
le 23 Fév 2021
Commenté : andrew krugle
le 24 Fév 2021
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 commentaires
Rik
le 23 Fév 2021
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.
Réponse acceptée
Walter Roberson
le 24 Fév 2021
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 commentaires
Walter Roberson
le 24 Fév 2021
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!