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