How can I Save data from for loop into an array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have been trying to save the data generated in the T matrix for the six for loops in an array consist of 15,625 page where each page contains the 4x4 T matrix generated inside the six for loops. There are six for loops for six preceding variables each with a 5 numbers so the total result is 5^(6) solutions possible for the T matrix. Here I have attached the code I used to solve the matrix and is there anything I can do to increase the solving time, I sense the use of six for loops seems a bit obsolete. the code;
d4=10;
for d1=-15:8.75:20;
for d2=-12:6:12;
for d3=0:6:24;
for Theta4=-90:45:90;
for Theta5=-45:56.25:180;
for Theta6=-90:33.75:45;
T06=[sind(Theta4), cosd(Theta5), sind(Theta6), d1; cosd(Theta4), sind(Theta5), cosd(Theta6), d2; sind(Theta4), cosd(Theta5), sind(Theta6), d3+d4; 0, 0, 0, 1];
end
end
end
end
end
end
2 Commenti
Image Analyst
il 19 Mar 2022
T06 gets overwritten every iteration. How do you want to save it? To a 6-dimensional array? Or write the current T06 out to a text file with fprintf()?
Risposte (1)
Walter Roberson
il 19 Mar 2022
d4 = 10;
d1vals = -15:8.75:20;
d2vals = -12:6:12;
d3vals = 0:6:24;
Theta4vals = -90:45:90;
Theta5vals = -45:56.25:180;
Theta6vals = -90:33.75:45;
[vars{1:6}] = ndgrid(d1vals, d2vals, d3vals, Theta4vals, Theta5vals, Theta6vals);
vars = cellfun(@(C) reshape(C, 1, 1, []), vars, 'uniform', 0);
d1 = vars{1}; d2 = vars{2}; d3 = vars{3}; Theta4 = vars{4}; Theta5 = vars{5}; Theta6 = vars{6};
Z = zeros(size(Theta4));
ONE = ones(size(Theta4));
T06 = [sind(Theta4), cosd(Theta5), sind(Theta6), d1;
cosd(Theta4), sind(Theta5), cosd(Theta6), d2;
sind(Theta4), cosd(Theta5), sind(Theta6), d3+d4;
Z, Z, Z, ONE];
whos T06
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!