Reading txt file in GUI

4 views (last 30 days)
Luis Eduardo Cofré Lizama
Commented: Image Analyst on 29 Jul 2020
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 Comments
Image Analyst
Image Analyst on 28 Jul 2020
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"
Maria
Maria on 29 Jul 2020
Sure, thanks!

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 28 Jul 2020
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 Comments
Luis Eduardo Cofré Lizama
Thansk for the quick answer. I recently changed a bit and combined EditField and DropDown (I tried the above but didnt work). So the full story is as below:
BTW I am assuming that i\f I have 2 elements in the drop down (case of MS and HC) the first will give a value 1 and second one 2
group = {'MS','NS'};
condition = {'E0C0','E1C0','E0C1','E1C1'};
g = app.GroupDropDown.Value;
gr = group(g);
p = app.ParticipantEditField.Value;
s = app.SessionDropDown.Value;
c = app.ConditionDropDown.Value;
cd = condition(c);
t = app.TrialDropDown.Value;
fullFileName = char(strcat(pwd,'\',gr,num2str(p),'S',num2str(s),cd,'T',num2str(t),'.txt'));
if ~isfile(fullFileName)
warningMessage = sprintf('Warning: file does not exist:\n%s', fullFileName);
fprintf('%s\n', warningMessage);
uiwait(errordlg(warningMessage));
return;
end
Am new at app designer so sorry if am making something obvious
cheers
eduardo
Image Analyst
Image Analyst on 29 Jul 2020
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

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!