how extract specific values from matrix and build separate arrays?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi there!
I have a function that generates a 4x4 matrix with different values at every iteration (100 matrices all up). I then want to get the 4th coulmn 1st row values of all these matrices in one array and the 4th column 2nd row in another array.
I could only think of a for loop to go through every matrix one at the time and extract the elemts required in each array but no success
Here is an example of what I am trying to acheive.
Any help would be much appreciated!
T(95) =
0.4982 0 -0.8671 1.495
0.8671 0 0.4982 2.601
0 -1 0 0
0 0 0 1
T(96) =
0.4989 0 -0.8666 1.497
0.8666 0 0.4989 2.6
0 -1 0 0
0 0 0 1
T(97) =
0.4995 0 -0.8663 1.498
0.8663 0 0.4995 2.599
0 -1 0 0
0 0 0 1
T(98) =
0.4998 0 -0.8662 1.499
0.8662 0 0.4998 2.598
0 -1 0 0
0 0 0 1
T(99) =
0.4999 0 -0.8661 1.5
0.8661 0 0.4999 2.598
0 -1 0 0
0 0 0 1
T(100) =
0.5000 0 -0.8660 1.5
0.8660 0 0.5000 2.598
0 -1 0 0
0 0 0 1
for i=1:100
a1(i)=T(i)(4,1)
a2(i)=T(i)(4,2)
end
%resut:
a1=[......1.495 1.497 1.498 1.499 1.5 1.5]
a2=[[...... 2.601 2.6 2.599 2.598 2.598 2.598]
2 comentarios
Walter Roberson
el 25 de Abr. de 2020
T(95) =
0.4982 0 -0.8671 1.495
0.8671 0 0.4982 2.601
0 -1 0 0
0 0 0 1
Is that form, complete with the (95), being output to a text file? Or is that being output to the command window? Do you have access to the source code to be able to put the outputs into a cell array or a 3D array?
Respuestas (1)
KALYAN ACHARJYA
el 25 de Abr. de 2020
Editada: KALYAN ACHARJYA
el 25 de Abr. de 2020
One Way: Indexing
%generates T in 3D
T(:,:,1)= [0.4982 0 -0.8671 1.495
0.8671 0 0.4982 2.601
0 -1 0 0
0 0 0 1]
T(:,:,2)= [0.4989 0 -0.8666 1.497
0.8666 0 0.4989 2.6
0 -1 0 0
0 0 0 1]
T(:,:,3)=[0.4995 0 -0.8663 1.498
0.8663 0 0.4995 2.599
0 -1 0 0
0 0 0 1]
T(:,:,4)= [0.4998 0 -0.8662 1.499
0.8662 0 0.4998 2.598
0 -1 0 0
0 0 0 1]
T(:,:,5)= [0.4999 0 -0.8661 1.5
0.8661 0 0.4999 2.598
0 -1 0 0
0 0 0 1]
T(:,:,6)= [0.5000 0 -0.8660 1.5
0.8660 0 0.5000 2.598
0 -1 0 0
0 0 0 1]
Then easy to extract the required data
>> whos T
Name Size Bytes Class Attributes
T 4x4x6 768 double
>> ar1=T(1,4,:)
ar1(:,:,1) =
1.4950
ar1(:,:,2) =
1.4970
ar1(:,:,3) =
1.4980
ar1(:,:,4) =
1.4990
ar1(:,:,5) =
1.5000
ar1(:,:,6) =
1.5000
Later you can go for 3D o 1D
5 comentarios
Walter Roberson
el 25 de Abr. de 2020
The Peter Corke fkine() method returns an SE3 object. If you have that SE3 object, then you can use the R method to get a 3D array of rotations.
t = [0:.056:2]; % generate a time vector
q = jtraj(qz, qr, t); % compute the joint coordinate trajectory
T = p560.fkine(q);
Now
Rots = T.R;
Rots would be 3 x 3 x 36 where 36 is the number of poses (one for each t value in the above)
Ver también
Categorías
Más información sobre ROS Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!