Borrar filtros
Borrar filtros

How to access values in struct from another script?

12 visualizaciones (últimos 30 días)
Laurel Castillo
Laurel Castillo el 1 de Dic. de 2018
Editada: Stephen23 el 1 de Dic. de 2018
Hi all,
So I have a script as below with some data in struct.
For example, I want to access the value 1.2 in the struct, when I am working on another script (e.g. CAL.m) for manipulation. What code should I use?
If the 1.2 is in a matrix named DH in the CAL.m, I can access it with DH(1,4) in CAL.m
But now the DH is a struct and located in ArmModel.m, how can I acess its values in CAL.m?
The purpose here is to store some data in the script ArmModel.m, and then access the data from another script CAL.m. So I can plug other dataset maybe ArmModel2.m, ArmModel3.m...... into CAL.m later.
Thanks!
function m = ArmModel()
l_RCC = 0.4318;
l_tool = 0.4162;
l_pitch2yaw = 0.0091;
m.DH = [
% type alpha a d theta
% ==== ===== = = =====
1 pi/2 0 1.2 pi/2 ;
1 -pi/2 0 0 -pi/2 ;
2 pi/2 0 -l_RCC 0 ;
1 0 0 l_tool 0 ;
1 -pi/2 0 0 -pi/2 ;
1 -pi/2 l_pitch2yaw 0 -pi/2 ;
];
end

Respuesta aceptada

Stephen23
Stephen23 el 1 de Dic. de 2018
Editada: Stephen23 el 1 de Dic. de 2018
Just return that structure when you call ArmModel inside CAL.m:
m = ArmModel();
DH = m.DH;

Más respuestas (0)

Categorías

Más información sobre Structures 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!

Translated by