app designer brining in variables from a script
조회 수: 7 (최근 30일)
이전 댓글 표시
Hopefully I can explain this:
I am working on an app where the user can load in csv files. The csv files are vehicle data from CANbus and so naturally, different vehicles can have different header names for the same thing like vehicle speed. The data are read in using readtable, so normally in my typical matlab script, the data comes in as a table.
So my idea was, once the user had loaded in the vehicle data. They would then load in a script file that contained the right mappings. So what I am trying to do is map the differing names to some standard names that can then be used throughout the app.
But I am a bit stuck on how you actually get them in. I know you can use run() to run the script, but obviously you can't see the variables.
would I add my standard names in the app as properties first? so for example: app.VehicleSpeed.
Then in the script i have app.VehicleSpeed = app.importedfile.CANbus_name?
댓글 수: 2
Kevin Holly
2022년 4월 26일
편집: Kevin Holly
2022년 4월 26일
You could turn the script into a function MATLAB file and call it with the variables you need as the inputs. Also, run() is not needed to run your script. You could just type the name of the script.
For the function inputs, you do not need to use the app's property variables. If the function is called within one of the app's callback function and all variables are in that callback's workspace, then you just simply input the variables into the function. If you want to use properties variables as inputs, you could use them as inputs to the function as a single variable (app.variable) or as a structural array (app), which you can use to call all the app's properties within your function. Let me know if you would like me to provide an example.
채택된 답변
Kevin Holly
2022년 4월 27일
편집: Kevin Holly
2022년 4월 27일
Alex,
I have attached an app that loads Excel data as a table and then calls a live function called "TableConverter" that replaces the heading variables names of the table. When I called the function, I placed the table variable as the input. I did not use app properties. If I did choose to do this, I could call a table that is saved as a properies, such as "InputTable", into the function and then call it with "TableConverter(app.InputTable)" . Alternatively, I could place all the app's property variables into the function by with the command, "TableConverter(app). Then within the function, I could access a particular variable such as "app.InputTable".
댓글 수: 3
Kevin Holly
2022년 4월 28일
I wasn't sure how much manipulation was involved when converting the table. I wasn't sure how complicated the script you were using was. For instance, you may have needed to import the data as an array, tranpose the matrix, and then convert the array to a table with an array2table function. Or you might have filtered the table for certain values related to a header. Or you might have multiplied the values by let's say a thousand for it to be equilivant to another header or multiply them by a constant for unit conversion. That is why I used a switch case, to leave room for addtional changes to table.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Downloads에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!