# How to store a matrix output of a loop?

12 views (last 30 days)
azarang asadi on 1 Feb 2020
Commented: azarang asadi on 2 Feb 2020
Here's my code:
(tryna get the transformation matrices of each link of a robot and save them)
g=zeroes(4); %initial global frame
for j=1:7
theta=q(j);
alpha=al(j);
0,0,0,1];
end
I need to have 7 matrices corresponding to the transformation of each link like g(1),g(2), ....

Walter Roberson on 1 Feb 2020
Edited: Walter Roberson on 1 Feb 2020
g=zeroes(4, 4, 7); %initial global frame
for j=1:7
theta=q(j);
alpha=al(j);
0,0,0,1];
end
Now g(:,:,k) will be the k'th matrix.
If you prefer,
g = cell(7, 1); %initial global frame
for j=1:7
theta=q(j);
alpha=al(j);
0,0,0,1];
end
and then g{k} would be the k'th matrix.
azarang asadi on 2 Feb 2020
first one didn't work but the second one worked, thanks

### Categories

Find more on Robotics in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!