Import Data from html-built UI to Matlab

조회 수: 18 (최근 30일)
Jovelyn Obias
Jovelyn Obias 2021년 11월 15일
댓글: Antonio Hortal 2021년 11월 19일
Hello. I've created user interface (a form) using HTML and CSS and embedded it onto matlab using uihtml component. I've successfully loaded my UI through matlab however, I cannot fetch the data entered from the UI. I need those data and input them in my anfis model which is generated through NeuroFuzzy Designer here in matlab. After the data processed through the model, i then need to display the result onto my UI. Main goal of my project is to predict risk level of patients in getting pneumonia. Question is, how can I fetch data from my UI and pass it to matlab, and vice versa?

채택된 답변

Antonio Hortal
Antonio Hortal 2021년 11월 15일
Hi Jovelyn, I can recommend you to go through this article that explains how the "Data" property in the uihtml component lets you connect your Matlab code with your HTML one: "Create HTML File that can trigger and respond to data changes". The documentation for the uihtml object also has some nice examples on how to set up the connection between Matlab and HTML
For your form you could try something like this:
  1. In your html file, create a setup function (like in the article) that appends a submit listener to your form element. When registering a submit event, you will need to change the "Data" property of the htmlcomponent to whatever you want your Matlab code to see.
function setup(htmlComponent) {
document.getElementById('yourFormId').addEventListener('submit', function (event){
htmlComponent.Data = {'Name': document.getElementById('yourFormInput').value};
})
}
2. In Matlab, add a 'DataChangedFcn' callback to your uihtml element. The second argument to the callback (the event) contains the "Data" that was sent from the HTML file
yourUIHTML.DataChangedFcn = @(src, event) dataChangedCallback(src, event);
function dataChangedCallback(src, evt)
yourHTMLData = evt.Data;
disp(yourHTMLData.Name)
end
  댓글 수: 10
Jovelyn Obias
Jovelyn Obias 2021년 11월 18일
Sorry for adding another question, inside the script tag can i add another function for may html functionalities? Cause when i added function, "htmlsource may be referencing unsupported functionality or may have a javascript error" appears just after entering answer in the first question. I think the setup function is being triggered immediately
Antonio Hortal
Antonio Hortal 2021년 11월 19일
You can creare as many functions as you want in your <script> tags inside the HTML file.
The warning message that you get in the command window is thrown when your javascript code throws an error. On this article there is a section called 'Debug your HTML code', give it a try :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by