How can I send a value from GUI to constant block in Simulink Model?

I have threee constant block. And I want to value to those from GUI when ı pushed the button after ı take value from edit text blocks.

 Réponse acceptée

As far as I know, edit text blocks takes input arguments as string. What you need to do is to use set_param command and convert the variables to double by using str2double command.
We have had a previous discussion about it, so please refer to that discussion. Here is an example:
set_param('gui/Constant','Value','i')
set_param('gui/Constant1','Value','j')
Do not forget to convert these values to double.

12 commentaires

yes ı did like that. but it gave me error like in figure. Parameters are sending well but value are not sending.
Birdman
Birdman le 12 Déc 2017
Modifié(e) : Birdman le 12 Déc 2017
set_param('byrm/Constant','Value','A1')
set_param('byrm/Constant1','Value','A2')
set_param('byrm/Constant2','Value','A3')
You need to properly define the path of the block in the first argument as I did. Please correct it for yourself. Also, the third arguments have to be the ones that you define in your GUI. Please make sure that they are the same. I wrote A1,A2 and A3 just for example. What are the parameters of edit text boxes in your GUI?
my edit text boxes parameters are psi, theta and phi. But after I calculated some operations and then I want to send A2,A3,A4. For example; A2=psi+theta, A1= psi*3 like these.
Do you define them like this? And please do not forget to convert them to double.
if true
% input1 = get(handles.edit1,'String');
input2 = get(handles.edit2,'String');
input3 = get(handles.edit3,'String');
psi=str2double(input1);
theta=str2double(input2);
phi=str2double(input3);
a=50;
s=125;
R=[cos(psi)*cos(theta),-sin(psi)*cos(phi)+cos(psi)*sin(theta)*sin(phi),sin(psi)*sin(phi)+cos(psi)*sin(theta)*cos(phi);sin(psi)*cos(theta),cos(psi)*cos(phi)+sin(psi)*sin(theta)*sin(phi),-cos(psi)*sin(phi)+sin(psi)*sin(theta)*cos(phi);-sin(theta),cos(theta)*sin(phi),cos(theta)*cos(phi)];
p=[-250,0,250;-250,250,-250;0,0,0];
T=[0,0,0;0,0,0;125,125,125];
b=[-200,-50,200;-250,250,-250;0,0,0];
l=T+(R*p)-b;
l1=sqrt((l(1,1)*l(1,1))+(l(2,1)*l(2,1))+(l(3,1)*l(3,1)));
l2=sqrt((l(1,2)*l(1,2))+(l(2,2)*l(2,2))+(l(3,2)*l(3,2)));
l3=sqrt((l(1,3)*l(1,3))+(l(2,3)*l(2,3))+(l(3,3)*l(3,3)));
L1=(l1.^2)-(s.^2-a.^2); L2=(l2.^2)-(s.^2-a.^2); L3=(l3.^2)-(s.^2-a.^2);
M1=2*a*(l(3,1)); M2=2*a*(l(3,2)); M3=2*a*(l(3,3));
N1=2*a*(cos(pi)*(l(1,1)+sin(pi)*l(2,1))); N2=2*a*(cos(0)*(l(1,2))+sin(0)*l(2,2)); N3=2*a*(cos(0)*(l(1,3))+sin(0)*l(2,3));
U1=M1^2+N1^2; U2=M2^2+N2^2; U3=M3^2+N3^2;
J1=N1/M1; J2=N2/M2; J3=N3/M3;
i=(asin(L1/sqrt(U1))-atan(J1))*57.32; j=(asin(L2/sqrt(U2))-atan(J2))*57.32; k=-1*(asin(L3/sqrt(U3))-atan(J3))*57.32; set_param('byrm/Constant','Value','i'); set_param('byrm/Constant1','Value','j'); set_param('byrm/Constant2','Value','k'); end
It does not mean anything for me to see your code. Does it still give error?
the constant block's names are true. But value of parameters are not sending. I did not understand why. Then error says undefined function or variable. Actually firstly ı run GUI. then I am openıng my sımulınk model after that ı run the simulink model.
You should first open the model, then run the GUI.
I think somethings is wrong. I am so sorry. I asked so many question. But when I pushed the button, ı want to see true values in displat that connect to constan blocks. But ı can not see.
thank you. desired value are send to display and I saw true value.
Okay that's good.
this is not recommended...
@Birdman: yet you recommend it.
@bayram özmen: Please be warned about the risks associated with using assignin.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by