How Can I Show a txt File in a GUI ?

22 ビュー (過去 30 日間)
Serhat Sayim
Serhat Sayim 2021 年 3 月 5 日
回答済み: Jorg Woehl 2021 年 3 月 5 日
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 ?

採用された回答

Jorg Woehl
Jorg Woehl 2021 年 3 月 5 日
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.).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by