GUI push button help

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 个评论

Normally when you code you get your variables in the workspace section - is this also something that happens with the GUI? Or do the variables just not appear? I try coding it bit by bit in the command window and there it works but as soon as I place the same code in the editor section it just doesn't seem to do much.
I looked at some youtube videos but they just use the editor window to put in their codes but how do you trouble shoot this if it doesn't work and I don't have the variables in the workspace section?
thank you for the suggestions I will take a look !
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.
Thank you so much!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

提问:

2022-2-5

评论:

2022-2-5

Community Treasure Hunt

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

Start Hunting!

Translated by