Is there a way to save the c3d files using the uigetfile function in the order that you select rather than have them be imported in alphabetical order?

14 views (last 30 days)
In the following lines I am trying to import .c3d files (which are files that contain 3D data from trials captured with motion capture software (vicon), and processed through the vicon nexus software. See the Trials.zip folder for the c3d jump trials and since I can only upload a max of 5MB of files/data, I have uploaded only 3 unique c3d files.
To read the c3d files I am using the btk (biomechanical toolkit)... I have attached the btk file that you need to add to the path when you run your script.
Now what I have been trying to do is save the .c3d files in the order that I select them from the dialog box for both versions of my script. However what has happened is that neither version imports/saves the files in the order that I select my c3d jumps. For example: if I click on the "Drop Jump.c3d" file, followed by "Reverse Drop Jump01.c3d" file... and finally the "Drop Jump Toe in01.c3d" file, that's how I would like them to be ordered on the
file_list
For the 2nd version I tried implementing the listdlg function but it does not really do much.
So I will restate my question again... Is there a way to either read the c3d files using uigetfile in the order that you select (which would make it the chronological order in my estimation) rather than have them be read/saved/arranged in alphabetical order?
I appreciate any help I can get.
Leo
1st version of my script
%This is the original code I had where I was relying solely on the
%uigetfile to read the c3d files
[file_list, path_n] = uigetfile('.c3d', 'Multiselect', 'on');
if iscell(file_list) ==0
file_list={file_list}
end
for i=1:length(file_list)
filename(i)=btkReadAcquisition(char(file_list(:,i)));
%Get jump type
%parse data
[angles(i), anglesInfo(i)]=btkGetAngles(filename(i));
[moments(i), momentsInfo(i)]=btkGetMoments(filename(i));
% [powers(i), powersInfo(i)]=btkGetPowers(filename(i));
% Events(i)=btkGetEvents(filename(i));
f2(i) = btkGetPointFrequency(filename(i));
[forces(i), forcesInfo(i)] = btkGetForces(filename(i));
% [forceplates{i}, forceplatesInfo{i}] = btkGetForcePlatforms(filename(i));
analog_data(i)= btkGetAnalogs(filename(i));
end
%%
2nd version
[file_list,path_n] = uigetfile('.c3d', 'Select files', 'MultiSelect', 'on');
if iscell(file_list) == 0
file_list = {file_list};
end
% Display custom dialog box to select files in the order they were selected
[file_index,~] = listdlg('PromptString','Select files in the order you want them to appear:',...
'ListString',file_list,...
'ListSize',[300 300],...
'SelectionMode','multiple');
file_list_sorted = file_list(file_index);
for i = 1:length(file_list_sorted)
% Read the file
filename = btkReadAcquisition(fullfile(path_n,file_list_sorted{i}));
% Get angles, moments, forces, etc.
[angles(i), anglesInfo(i)] = btkGetAngles(filename);
[moments(i), momentsInfo(i)] = btkGetMoments(filename);
f2(i) = btkGetPointFrequency(filename);
[forces(i), forcesInfo(i)] = btkGetForces(filename);
analog_data(i) = btkGetAnalogs(filename);
end
  8 Comments
Walter Roberson
Walter Roberson on 14 Apr 2023
The Mathworks logic is that it is better to call into the native operating system file selectors, so that you have consistent look-and-feel with the rest of the operating system, and you get to take advantage of whatever facilities the operating system may build in. For example when Microsoft Windows 11 Fall 2023 incorporates Chat-GPT into its file selection boxes, the facility will show up automatically.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 12 Apr 2023
uigetfile() calls out to native operating system facilities. There is no control over the order it returns items.
If you do not need to allow directory selection then you can dir() and throw the file names into a selection box, using the selection callbacks to record the order the user clicks. I did pretty much that at some point, to provide an improved multiselect experience, but I do not recall the details right now.
  3 Comments
Walter Roberson
Walter Roberson on 13 Apr 2023
h = uicontrol('style', 'listbox', 'max', 2)
Now set Callback . You will get called back for every click on the list. You will not want each selection (even of groups) to overwrite all previous selections, so you will need to track which items have been selected so far, and to un-select you will need the user to click back on the some item -- so when you get a selected item you will need to check if it is already selected and if so remove it from the selection list.
Leutrim Mehmeti
Leutrim Mehmeti on 16 Apr 2023
Edited: Leutrim Mehmeti on 16 Apr 2023
Okay so this is how far I have gotten.
If I just run the following I get nothing different than what I used to get with my previous attempts, however, if I run everything up to the following line:
file_list = get(listbox, 'String');
then I scroll down and manually change in the Figure...
(listbox, 'Value');
I get exactly what I need.
Is there a better way of doing this or is this as good as it is ever going to get?
See the full code including the function below!!
[file_list, path_n] = uigetfile('.c3d', 'Select files', 'MultiSelect', 'on');
if iscell(file_list) == 0
file_list = {file_list};
end
% Create listbox
figure('Units', 'normalized', 'Position', [0.4, 0.4, 0.2, 0.2]);
listbox = uicontrol('Style', 'listbox', 'String', file_list, 'Max', length(file_list), ...
'Min', 1, 'Units', 'normalized', 'Position', [0.1, 0.1, 0.8, 0.8]);
% Create button to sort files
button = uicontrol('Style', 'pushbutton', 'String', 'Sort Files', 'Units', 'normalized', ...
'Position', [0.4, 0.01, 0.2, 0.08], 'Callback', {@sort_files_callback, listbox});
function sort_files_callback(hObject, eventdata, listbox)
% Get the selected file names
file_list = get(listbox, 'String');
file_index = get(listbox, 'Value');
sorted_files = file_list(file_index);
% Save the sorted file names to a variable or do something else with them
disp(sorted_files);
files_sorted_final=sorted_files;
end

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks 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!