Load multiple files into GUI, in specific order
이전 댓글 표시
Hello,
I was wondering, is there a way to load multiple files into MatLab GUI, in the order of their selection? For example, lets say I have files: one.txt, two.txt, three.txt, four.txt. Now, if I say:
[FileNames PathNames]=uigetfile('*.txt', 'Chose files to load:','MultiSelect','on');
FileNames = cellstr(FileNames);
for i=1:length(FileNames)
Path{i} = fullfile(PathNames, FileNames{i});
fileID{i} = fopen(Path{i});
while ~feof(fileID{i})
C = textscan(fileID{i},'\t%f',1000000);
end
fclose(fileID{i});
Then, it will load files by alphabet, so when I plot, I will have on Xaxis: four, one, three, two . Therefore, I always have to rename files as: aone, btwo, cthree, dfour . Is it possible to avoid this and import files in the order of selection (by holding CTRL key)?
P.S. Dont mind if you spot an error in the code, I just gave it for better understanding.
댓글 수: 4
Geoff Hayes
2014년 5월 29일
I tried with the command key (on a Mac) and couldn't change the order of the selected files. It appears that their order (as written to the FileNames variable) is dependent upon how they are listed in the file chooser window - alphabetically by name, by size, modified date, etc.
Geoff says "it appears", the doc reports that "it is" -- under the multiselect section is included: File names in the cell array are sorted in the order your platform uses.
I looked at the Windows SDK documentation here and it doesn't appear that the information of "click order" is even available in the full-fledged uicontrol; what more the Matlab wrapper function around the system control.
Only way I see you've got would be to write a customized control that used the optional hook to an event handler inside the uicontrol and I didn't dig deep enough to tell just what events are seen by it on the presumption your interest didn't delve that deeply. :)
OTOMH, if you allow multi-select, I don't see any way to get what you're looking for. This might be a question for MSDN (presuming again you're on Windoes).
ADDENDUM
Of course, if you don't allow multi-select but did arrange to return to the dialog after a single, then you can save them in the order returned...probably not something a user would fall in love with, however...
If there were always going to be a relatively small number of files, you could perhaps populate a listbox and allow the selection from it such that you could ascertain the order selected...again, seems kinda' clunky.
Not sure I see away other than perhaps to allow the multiselect, then present those selected and ask for them to be ordered by user. Other than that would seem would have to have some internal logic to be able to make an order that meets some criterion if there's some naming scheme or whatever.
Geoff Hayes
2014년 5월 29일
I was able to select the same set of files and have them appear in a different order in the FileNames variable depending upon how the files were sorted in the uicontrol - alphabetically, by modified date, by size, etc. but not by the order in which the files were selected (by me). So it doesn't matter which order I select them in, it just depends upon the order in which they are listed in the uicontrol.
dpb
2014년 5월 29일
Yes, that's what the doc says...they're returned "sorted in the order your platform uses". It uses at that time the order as selected in the uicontrol via the sorting as selected in the view (I presume that's how you changed the order?).
But, as noted, there's not any place in the OPENFILENAME structure for the info on order selected to be returned by using a wrapper around a native uicontrol call eschewing the Matlab somewhat emasculated wrapper function.
답변 (1개)
Image Analyst
2014년 5월 30일
0 개 추천
If all your files are in the same folder, it's fairly easy. You just use a listbox instead of uigetfile(). By making the selection be a persistent or global variable , and by checking it in the listbox callback to see how it changes with each click , you can use ismember to build up a list of selected items in the order they clicked. Hopefully that's a good enough explanation for you to do it, because I didn't have time to program it up for you.
If they're in different folders, you can still do it with extra case to keep track of which folder each item in your listbox came from but since your current method uses uigetfile() I don't think different folders is the case with you.
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!