Reading txt file in GUI

조회 수: 1 (최근 30일)
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama 2020년 7월 27일
댓글: Image Analyst 2020년 7월 29일
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
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"
Maria
Maria 2020년 7월 29일
Sure, thanks!

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
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
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama 2020년 7월 29일
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 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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by