MATLAB Answers

PAK
0

sort a cell array of file paths by portions of the file path

Asked by PAK
on 9 Jan 2019
HI All,
I have an output from the dirrec function, which is a 12x1 cell array, where each cell is a file path. Example below. I need to sort this array in a very specific way, because I'd like to concatenate the variables within the matfiles that have the same name (but only for the matfiles that have the same filename as specified by the paths below). I had thought that the easiest way to do this would be to sort it first by the 'Neg' or 'Pos' portion of the file path, then by the '1_50_Hz' , '50_100_Hz' etc, portion of the file path, and then to sort by the filename (within the file path). Then I would just loop through the files and concatenate. Would anyone know a quick way to do this?
Thank you!
PAK
Cell array "X":
X{1,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/1_50_Hz/001/NS3_001_NS6_002.mat
X{2,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/1_50_Hz/001/NS3_001_NS6_007.mat
X{3,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Pos/Phase_Locking/1_50_Hz/001/NS3_001_NS6_006.mat'
X{4,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/50_100_Hz/001/NS3_001_NS6_002.mat'
X{5,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/50_100_Hz/001/NS3_001_NS6_007.mat'
X{6,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Pos/Phase_Locking/50_100_Hz/001/NS3_001_NS6_006.mat'
X{7,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/100_150_Hz/001/NS3_001_NS6_002.mat'
X{8,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/100_150_Hz/001/NS3_001_NS6_007.mat'
X{9,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Pos/Phase_Locking/100_150_Hz/001/NS3_001_NS6_006.mat'
X{10,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/150_200_Hz/001/NS3_001_NS6_002.mat'
X{11,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Neg/Phase_Locking/150_200_Hz/001/NS3_001_NS6_007.mat'
X{12,1} = /Volumes/PAK/FR1_Local_Data/Current/UT084/Analysis_Retrieval/AH/Pos/Phase_Locking/150_200_Hz/001/NS3_001_NS6_006.mat'

  0 Comments

Sign in to comment.

Products


Release

R2018a

0 Answers