How to pass data from Edit Text Box in GUI to Constant Block in Simulink?

Hi everyone..
I have a GUI and Simulink (from Simmechanics), and I want to import a data from Edit Text Box in GUI to Constant Block in Simulink. But I don't know how to make it. Is there anyone who can help me?
Thankyou for your attention...

 채택된 답변

Sachin Ganjare
Sachin Ganjare 2012년 10월 18일

1 개 추천

댓글 수: 2

Use 'assignin' function in GUI function callback for updating value of variable that is used in constant block.
Thanks for your fast response. I have tried but still I didn't understand by using workspace. I hope I'll use set_param commands. Maybe you can lead me to the link who show about set_param using and example.
Thank you..

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 20일
편집: Azzi Abdelmalek 2012년 10월 20일
c=10
set_param('yourmodelname/Constant','value',num2str(c))
%yourmodelname is your simulink model name

댓글 수: 9

Yoga
Yoga 2012년 10월 20일
편집: Yoga 2012년 10월 20일
This is which I wrote at GUI Edit Text Box Callback.
u = get(hObject,'String');
set_param('untitled/Constant','value',num2str(u));
but it doesn't works.. Is there anything wrong?
just check if your constant block is named "constant" , if you have many constant blocks, they are named constant, constant1;...
Yoga
Yoga 2012년 10월 21일
편집: Yoga 2012년 10월 21일
Oh.. But I only have 1 constant block.
Yoga
Yoga 2012년 10월 21일
편집: Yoga 2012년 10월 21일
Ahh I know the problem.. It should be :
u = str2double(get(hObject,'String'));
And now, it works properly. Thank you very much for your helps..
I've used it and it works. I can't tell, maybe there are some names which are 'nt correct
Is there an error message, or what? also, when you use set_param, your simulink model must be open, or at least must be loaded.
load_system('untitled')
Yoga
Yoga 2012년 10월 22일
편집: Yoga 2012년 10월 22일
No,no, It works now. The problem is I did'nt use str2 double, so it should be :
u = str2double(get(hObject,'String'));
Thank you very much for your helps..
I have sine wave block instead of constant block how can i update the values of amplitude and frequency in gui with simulink?
@ Azzi Abdelmalek
I used your command:
c=10
set_param('yourmodelname/Constant','value',num2str(c))
but it does not work with step block. Do you know the command for step block. thanks

댓글을 달려면 로그인하십시오.

hellos everyone . I am now working on a project that is the regulation of the temperautre and humidity with the help of the Arduino + DHT11 sensor and Simulink , I connected a script matlab in series with the Arduino software to extract values humidity and temperature to plots them in a graph. I'd like to display these values in Simulik for the regulation of these values ,I got Many problem at the declaration of set- param function here is the matlab code (exmeple Tepmerature ): global Temp ; Temp(i) = str2num(out(1:4));
set_param('DHT11SIM/Temperature','value',num2str(Temp))
set_param('DHT11SIM', 'Temperature', 'update')
subplot(211); plot(Temp,'g'); axis([0,temps,20,50]); title('DHT11 Température'); xlabel('---> temps (secondes)'); ylabel('---> Température'); grid
code simulink:
here is the erruer that always receives: Error using DHT (line 15) Invalid Simulink object name: DHT11SIM/Temperature .
please Help me

카테고리

태그

질문:

2012년 10월 18일

편집:

2018년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by