How to call funcitons inside a loop ? To automate my testing
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chirag
el 12 de Dic. de 2022
Comentada: Bora Eryilmaz
el 15 de Dic. de 2022
I am new to Matlab and working on an Antenna testing system with Keysight instruments. I want to automatize my task with a loop and for that I need 3 input arguements to intiate the process. this is what I have tried so far:
function Auto_test (times, degrees, seconds)
for steps = 1:times % steps = how many times I need to rotate the motor
Step_Size = steps * degrees; % degrees = for ex. I need 30" step size for every rotation
MyArcus.PositionTo(Step_Size); % it's a funciton from another .m file for a stepper motor
pause(1.5)
% both of these functions from other .m file to collect the current marker's value for every single step from an analyzer
obj.Get_Marker_Power(1); % '1' is a selected marker's number
obj.Get_Marker_Freq(1);
pause (seconds)
end
pause(2);
MyArcus.PositionTo(0); % at the end motor comes back to 0 position
end
now when I try to run this code "my motor works with 100% accuracy" but (obj.Get_Marker_Power(1) and the other) shows an error.
an error
% Unable to resolve the name obj.Get_Marker_Power.
%
% Error in Auto_test (line 21)
% obj.Get_Marker_Power(1);
also I need to store the values of "Steps, power and freq." in a table for a graph
As I have spent 2 week only to understand the loops, I have an idea that functions can not be called inside loop. But I do not have any idea how to imporve my code according to my requirement. Please help me here.
3 comentarios
Bora Eryilmaz
el 12 de Dic. de 2022
See my answer below. I think you need the first approach I've listed there.
Respuesta aceptada
Bora Eryilmaz
el 12 de Dic. de 2022
Editada: Bora Eryilmaz
el 13 de Dic. de 2022
The variable called "obj" in your function is not defined anywhere in your code. You either need to pass it into the function as an input argument or you need to create it somewhere inside the function.
Looks like you need something like:
obj = MyArcus; % Instantiate the device once
...
obj.PositionTo(Step_Size); % Call methods using the object reference.
obj.Get_Marker_Power(1);
or
obj = MyArcus; % Instantiate the device once
MyArcus.PositionTo(Step_Size); % Since some methods are static, you can use class name, too.
...
MyArcus.Get_Marker_Power(1);
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Construct and Work with Object Arrays 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!