how to Make a button upload a .txt file and another button to read the file and plot it in matlab app design?
11 次查看(过去 30 天)
显示 更早的评论
Do you have any tips in making my buttons work, i did the code in normal matlab and it works but i dont know how to translate it in app designer
- the code in calculate button should plot a line graph showing the peaks
This is for my upload button, it should keep the file "data.txt"
% Button pushed function: UploaddataButton
function UploaddataButtonPushed(app, event)
[file,path] = uigetfile('*.txt')
end
This is for my "calculate" button, the code should read the uploaded file and plot the graph
% Button pushed function: CalculateButton
function CalculateButtonPushed(app, event)
fid=fopen('Data.txt');
s=textscan(fid,'%f %f','headerlines',2);
g = cell2mat(s);
x=g(:,1);
y=g(:,2);
[sortedX, sortIndex] = sort(x);
sortedY = y(sortIndex);
sortedXLimit = sortedX(1:160,:);
sortedYLimit = sortedY(1:160,:);
findpeaks(sortedYLimit,sortedXLimit,'MinPeakProminence',205,'Annotate','extents')
[psor,lsor] = findpeaks(sortedYLimit,sortedXLimit,'MinPeakProminence',205,'SortStr','descend')
set(gca, 'XDir','reverse')
text(lsor+.02,psor,num2str((1:numel(psor))'))
end
0 个评论
采纳的回答
Adam Danz
2020-4-28
When you select the file with uigetfile, the outputs need to be stored as a property of the App so all callback functions have access to the files selected.
Here's instructions how to set the file and path variables as app properties and here's a demo you can follow.
In your CalculateButtonPushed function, after the file and path variables have been declared as properties, you can access the user's selection:
fid=fopen(fullfile(app.Path, app.File));
% ^^^^^^^^ ^^^^^^^^^ replace with your var names
3 个评论
Adam Danz
2020-4-28
My understanding is that this function,
function UploaddataButtonPushed(app, event)
[app.file, app.path] = uigetfile('*.txt')
end
allows the user to select a file and the outputs are stored as properties of the app. The that file is read by,
fid=fopen(fullfile(app.Path, app.File));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!