GUI push button help

조회 수: 3 (최근 30일)
Jo Smi
Jo Smi 2022년 2월 5일
댓글: Jo Smi 2022년 2월 5일
I am so sorry to be asking this. I am new to the whole gui enviornment and I feel a bit lost with it.
I am trying to create a push button, which lets me upload data and then graph the data. The file I want to upload has 3 columns: date / time / activity. I want to be able to upload this data with the push button and to graph time and activity.
So far I have made this
[dataFile, dataPath] = uigetfile('*.*');
data=[dataPath dataFile];
[fid, msg] = fopen(dataFile, 'r');
and it only lets me select my file but it doesn't seem to upload it. Am I missing something trivial? I am so sorry if this is a stupid question I am learning matlab now...
thank you!

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 2월 5일
편집: Cris LaPierre 2022년 2월 5일
What error message are you getting?
You probably need to use fullfile to properly construct the path+filename, and then use that to load your file. See the examples on the uigetfile documentation page.
Also, fopen does not load a file. It opens it so you can then read it in. I suggest using readtable. This will load the data into a table, so see the Access Data in a Table page for how to work with this data type.
[dataFile, dataPath] = uigetfile('*.*');
data=fullfile(dataPath,dataFile);
[fid, msg] = readtable(data);
You might also find it helpful to go through the app designer tutorial. Following that, there are several examples you can load and look at and learn from.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2022년 2월 5일
No, guis operate in their own workspace. You will not see the results in the MATLAB workspace. Think of it as writing functions. You can still inspect your code as you are used to doing, but you will need to learn to use the debugging tools in order to do so.
Jo Smi
Jo Smi 2022년 2월 5일
Thank you so much!

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by