MATLAB: Error using set in GUI

errorguisetstatictext

Hi! Could someone help me solve this error please?
Code in a different workspace:
function fun = Proy(t,x)
global tiempo
global k
Ca1 = x(1);
Cb1 = x(2);
Ca2 = x(3);
Cb2 = x(4);
Cao = 20;
fun (1) = 1/tiempo*(Cao - Ca1) - (k*Ca1);
fun (2) = -1/tiempo*Cb1 + (k*Ca1);
fun(3) = 1/tiempo*(Ca1 - Ca2) - (k*Ca2);
fun (4) = 1/tiempo*(Cb1 - Cb2)-(k*Ca2);
fun = fun';
Code in my GUI:
global tiempo
global te
global R
global k
contenido = get(handles.opcion,'Value');
switch contenido
case 1
k = 0.0157;
case 2
k = 0.12;
case 3
k = 0.089;
case 4
k = 0.35;
end
tiempo = eval(get(handles.residencia,'String'));
xo = [0 0 0 0];
if tiempo <= 10
tint = [0,100];
[t,x] = ode45 (@Proy, tint, xo);
elseif tiempo <= 45
tint = [0,250];
[t,x] = ode45 (@Proy, tint, xo);
else
tint = [0,450];
[t,x] = ode45 (@Proy, tint, xo);
end
Ca1 = x(:,1);
Cb1 = x(:,2);
Ca2 = x(:,3);
Cb2 = x(:,4);
R = get(handles.sitime,'Value');
if R == 1
te = eval(get(handles.TE,'String'));
Ca1e = x(te,1);
set(handles,Ca1,'Value',Ca1e);
Cb1e = x(te,2);
set(handles,Cb1,'Value',Cb1e);
Ca2e = x(te,3);
set(handles,Ca2,'Value',Ca2e);
Cb2e = x(te,4);
set(handles,Cb2,'Value',Cb2e);
elseif R == 0
Ca1 = x(:,1);
set(handles,Ca1,'Value',Ca1);
Cb1 = x(:,2);
set(handles,Cb1,'Value',Cb1);
Ca2 = x(:,3);
set(handles,Ca2,'Value',Ca2);
Cb2 = x(:,4);
set(handles,Cb2,'Value',Cb2);
C = [Ca1 Cb1 Ca2 Cb2];
set(handles,Ctot,'Value',C);
end
Error shown:
Error using set
Conversion to double from struct is not possible.
Error in trialproy_>calcular_Callback (line 160)
set(handles,Ca1,'Value',Ca1e);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in trialproy_ (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)trialproy_('calcular_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
I just want to display the result of my variables (e.g. Ca1e) in a static text. Thanks!
Btw: I tried using String instead of Value and it doesn't work either.

Best Answer

I guess, that static text has the handle "handles.Ca1". Then:
set(handles.Ca1, 'String', sprintf('%g', Ca1e));
% ^ dot, not comma
This concerns the other set() commands of your code also.
Setting the 'Value' does not seem reasonable. The Values of uicontrols are e.g. the on or off status of a toggle buttons or check boxes, or the current value of a slider, or the indices of selected elements of a listbox. The appearing string is defined by the 'String' property.
If you get an error message like:
Error using set
Conversion to double from struct is not possible.
and do not understand it, the first thing to do is reading the docs:
doc set
There your find examples which shows, how the command is used. If this does not shed light on the problem already, use the debugger: Set a breakpoint in the failling line and run the code again. When it stops, check the value of the used variables:
% In: set(handles,Ca1,'Value',Ca1e)
handles
Ca1
Ca1e
Then compare the values with the documentation. For the set() command you would find, that it has 3 (or 5 or 7 etc) inputs, but not 4. The first is the handle, then the property and finally the new value. But in your case the first input is the handles struct, not one handle of a gui element.
These steps help you, to solve problems by your own.