Azzera filtri
Azzera filtri

How Can I Show a txt File in a GUI ?

9 visualizzazioni (ultimi 30 giorni)
Serhat Sayim
Serhat Sayim il 5 Mar 2021
Risposto: Jorg Woehl il 5 Mar 2021
I have a 5 txt file about informations of 5 different people . I designed a drop down menu about 5 people in the guı as you can see in the figure.For instance when I click to person 1 at the drop down it will show the first txt file. Should I put Edit field or text area into a guı to show the text files? How can I show these text files in the GUI ?

Risposta accettata

Jorg Woehl
Jorg Woehl il 5 Mar 2021
A text area would be the way to go, as it will show a scroll bar and wrap text if the content of the textfile is larger than the space available. Just make sure that you make it non-editable in App Designer (Inspector > Interactivity) if you only want to show the text but not allow the user to edit it.
I suppose you have one textfile per person. In this case, the callback for the dropdown menu could look similar to this:
value = app.DropDown.Value;
% choose the correct textfile depending on which person was selected
switch value
case 'Option 1'
myfile = 'person1.txt';
case 'Option 2'
...
end
% open the file and display its contents in the text area
fileID = fopen(myfile);
C = textscan(fileID, '%s', 'Delimiter', '\n');
app.TextArea.Value = C{1};
fclose(fileID);
To get to the callback, right-click on the dropdown menu and select Callbacks > DropDownValueChanged callback.
Note that you will have to adjust the callback code if you change the names of the options in the dropdown menu (Option 1, Option 2, etc.).

Più risposte (0)

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!

Translated by