How to upload a CSV file using a button on App Designer and using its content in another function.

조회 수: 32 (최근 30일)
I want to create an upload button and a plot button. The upload button will open a file browser and the user should be able choose the desired csv file. I want to read this csv as a table. Next using the plot button, I want to plot the values form that csv and analyze it further more.

채택된 답변

Jon
Jon 2022년 6월 28일
편집: Jon 2022년 6월 28일
I have attached a very rough example to get you started along with a data file to try it with.
Here are the main ideas (using App Designer):
  1. Drag and drop the buttons and an axes onto the app
  2. Define a property, e.g. app.dataTable, where the table of data that is to be read in is stored for use by callbacks
  3. Define ButtonPushed callback functions for the upload and plot buttons.
  4. The callback function for the upload uses uigetfile to let the user browse for the file, and reads the data into app.dataTable
  5. The callback function for the plot function uses the data stored in the app.dataTable property and plots it to the axes e.g. app.UIAxes, that is inside of your app. So use plot(app.UIAxes,x,y...) rather than plot(x,y). Otherwise a new figure window will open up outside of your app, and I don't think this is what you want.
The attached example is very basic, you would have to format things nicely, label your plot, make sure the user can't plot without first selecting a file etc.
  댓글 수: 4
R
R 2022년 6월 30일
편집: R 2022년 6월 30일
Thank you so much! Worked so well and made my code cleaner !!
To access variables from other functions, would app.function.variable work as well?
Jon
Jon 2022년 6월 30일
I'm not quite sure what you mean by "app.function.variable". In general the approach should be that if there is data that is shared between the callbacks, as in the above where one callback gets the filename, and reads in the data, and the other callback plots the data, then the common, shared data is stored as an app property, so in the above case app.dataTable

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by