Reading txt file in GUI
2 次查看(过去 30 天)
显示 更早的评论
Hi there. I was wondering whether is possible to read a specific *.txt file that is composed from selecting different values from the matlab app designer dropdown menus, BUT, skipping the dialogue box. So I pick, e.g., file 'E1S1T1.txt' and then plot content then select E2 from the dropdown menu and the file is "E2S1T1.txt' and so on. When I checked and open the file using dlmread( strcat(pwd,'\','E',num2str(s),'S,num2str(s),'T',num2str(t),'.txt')) and it all seems fine, but cannot incoporate to the GUI. Any suggestions please to solve this prob.
cheers
Eduardo
3 个评论
Image Analyst
2020-7-28
Maria, can you tranfer your answer down to the official "Answers" section with the other answers, instead of up here in the comments which is used to ask posters for clarification of the question? You can also get credit for it down there in terms of "reputation points"
回答(1 个)
Image Analyst
2020-7-28
If your drop down lists have numbers in them, and are named E, S, and T, then create a filename like this:
eValue = app.E.Value;
sValue = app.S.Value;
tValue = app.T.Value;
baseFileName = sprintf('E%dS%dT%d.txt', eValue, sValue, tValue);
fullFileName = fullfile(folder, baseFileName); % Folder is where the files live.
if ~isfile(fullFileName)
warningMessage = sprintf('Warning: file does not exist:\n%s', fullFileName);
fprintf('%s\n', warningMessage);
uiwait(errordlg(warningMessage));
return;
end
% else read in that file and do something with it.
2 个评论
Image Analyst
2020-7-29
I'm not using App Designer yet but if it's like GUIDE, the value property will be the index (1,2,3,...) of what item was selected, not the actual text of the item. You can get the String property to get all teh strings in the drop down list, then use the index to get the text, if you want/need it
index = app.Group.Value; %
allItems = app.Group.String; % MS and HC or whatever.
selectedText = allItems{index}; % 'MS' if that was selected or 'HC' if the second item was selected
另请参阅
类别
在 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!