Trying to load .mat file into App Designer and then graph it

11 ビュー (過去 30 日間)
Emma Peek
Emma Peek 2019 年 3 月 25 日
コメント済み: Emma Peek 2019 年 3 月 26 日
I am having a hard time trying to load a .mat file into the workspace and then have it graphed. In the simple app I've designed I have a push button and an axes. This is the code I have for the push button thus far. The button successfully opens a window in which I can choose a file but I can't get that file to load into the axes. What am I missing in my code?
The error that comes up is on the 'load('.mat') line and reads: Error using load Unable to read file '.mat'. No such file or directory.
Do I need to add the file I've opened to my directory? How would I do that?
Thank you so much.
% Button pushed function: MagicButton
function MagicButtonPushed(app, event)
uigetfile('.mat','Select a File')
load('.mat')
plot(app.UIAxes,[1;],'.mat')
app.UIAxes.YLim= [-1000 1000]
end

採用された回答

Kojiro Saito
Kojiro Saito 2019 年 3 月 26 日
You need to set file path from uigetfile then load it.
[file,path] = uigetfile('*.mat', 'Select a File');
if isequal(file,0)
disp('User selected Cancel')
else
load(fullfile(path,file))
plot(app.UIAxes,[1;], XXX); % XXX is variable contains in you mat file
app.UIAxes.YLim= [-1000 1000]
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by