how to Make a button upload a .txt file and another button to read the file and plot it in matlab app design?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
sydney salvador
il 28 Apr 2020
Commentato: Adam Danz
il 28 Apr 2020
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 Commenti
Risposta accettata
Adam Danz
il 28 Apr 2020
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 Commenti
Adam Danz
il 28 Apr 2020
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));
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!