how to Make a button upload a .txt file and another button to read the file and plot it in matlab app design?
조회 수: 2 (최근 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에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!