How Can I Show a txt File in a GUI ?

12 visualizaciones (últimos 30 días)
Serhat Sayim
Serhat Sayim el 5 de Mzo. de 2021
Respondida: Jorg Woehl el 5 de Mzo. de 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 ?

Respuesta aceptada

Jorg Woehl
Jorg Woehl el 5 de Mzo. de 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.).

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by