From: Javier on
Hi,

I'm quite newbie and have a question. I'm doing a GUI with GUIDE.
I need to perform a loop like this:

for i=0:3
...some stuff...
actuator=lcaGet(handles.ACTUATOR{(1+i)});
...other stuff...
end


This lcaGet function accepts only strings and handles.ACTUATOR = {'string1' 'string2' 'string3' 'string4'}
So I want to send to lcaGet each cycle loop one of this 4 strings like follows

i=0:
actuator=lcaGet('string1');
....
i=1:
actuator=lcaGet('string2');
....


I'm not sure how to manage it. Tried with sprintf but it just writes the variable name changing the number in { } but doesn't send the string.

Hope you understand the question.

Thanks in advance!
From: Steven Lord on

"Javier " <jagon(a)postal.uv.es> wrote in message
news:hunlg1$khk$1(a)fred.mathworks.com...
> Hi,
>
> I'm quite newbie and have a question. I'm doing a GUI with GUIDE.
> I need to perform a loop like this:
>
> for i=0:3
> ...some stuff...
> actuator=lcaGet(handles.ACTUATOR{(1+i)});

Assuming handles.ACTUATOR contains the contents you describe below, this
should work.

> ...other stuff...
> end
>
>
> This lcaGet function accepts only strings and handles.ACTUATOR =
> {'string1' 'string2' 'string3' 'string4'}
> So I want to send to lcaGet each cycle loop one of this 4 strings like
> follows
>
> i=0:
> actuator=lcaGet('string1');
> ...
> i=1:
> actuator=lcaGet('string2');
> ...
>
>
> I'm not sure how to manage it. Tried with sprintf but it just writes the
> variable name changing the number in { } but doesn't send the string.

Then either:

You're not using the code you wrote above, or
handles.ACTUATOR does not contain the contents you wrote above.

>> handles.ACTUATOR = {'string1', 'string2', 'string3'};
>> for i = 0:2
disp(handles.ACTUATOR{i+1})
end

results in the output:

string1
string2
string3

So instead of calling DISP as I did in the example, call lcaGet as you did
in your example.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com