replace_o_Accents = new ( " ", .Compiled) replace_i_Accents = new ( " ", .Compiled) replace_e_Accents = new ( " ", .Compiled) "C:\X\Project\PMSM\Demo\+task\+dataDictionary\t3_.Regex replace_a_Accents = new ( " ", .Compiled) You can split this using the STRSPLIT function files = strsplit(string(files))' files = The variable files is a single character array s = size(files) = system( 'dir /s/B C:\X\Project\PMSM\Demo\*.m') files =
Matlab 2012 split string special character windows#
On Windows systems you can perform a recursive directory search with the following example. You can apply operating system commands from MATLAB using the SYSTEM function. But it is a mechanism that I have used to perform similar functions to GLOB. This doesn’t necessarily reproduce all of the functionality that the GLOB function provides. Potential Alternative: Use Operating System Commands "C:\X\Project\PMSM\Demo\+task\+prototypeF28035\t1_openTestBench.m" "C:\X\Project\PMSM\Demo\+task\+pcgF28035\t4_openFloatingPointTestBench.m" "C:\X\Project\PMSM\Demo\+task\+pcgF28035\t3_loadAndPlotHwData.m" "C:\X\Project\PMSM\Demo\+task\+pcgF28035\t2_generateCodeAndCopyToParent." Now you can start applying common string methods like contains, endsWith, beginsWith, extractBetween, etc to filter and analyze the result hasF28035 = contains(files, 'F28035') My favorite feature of the STRING function is it can convert a cell array of character arrays to an array of Strings. "C:\X\Project\PMSM\Demo\+task\+dataDictionary\t3_partitionData.m" "C:\X\Project\PMSM\Demo\+task\+dataDictionary\t2_importEnums.m" "C:\X\Project\PMSM\Demo\+task\+dataDictionary\t1_openTestBench.m" "C:\X\Project\PMSM\Demo\+task\+dataDictionary\t0_initWorkFolder.m" The String class to the rescue! files = string(files) However, even in R2016b, DIR doesn’t support additional glob special characters like ? or character sets using or when extracting elements of the cell array. dir( 'C:\X\Project\PMSM\Demo\*\*.m') Files Found in: C:\X\Project\PMSM\Demo\+testįiles Found in: C:\X\Project\PMSM\Demo\Common Now, as of R2016b, you can use wildcard characters to perform recursive searches with the DIR function in MATLAB. Prior to R2016b the DIR function can only return elements found in the root of the search folder, and does not return elements found in child or subfolders. How does this differ from using the DIR function in MATLAB? There’s a good definition here along with some examples. The best well known is the "*" which represents any number of any characters. What’s a Glob?Ī glob is a pattern that includes wildcard characters that represent other sets of characters. Note:*** As of R2016b, the DIR function supports recursive searches. Here’s an example that finds all of the MATLAB-files in one of my larger projects: glob( 'C:\X\Project\PMSM\Demo\**.m') C:\X\Project\PMSM\Demo\startDemo.mĬ:\X\Project\PMSM\Demo\+task\+dataDictionary\t0_initWorkFolder.mĬ:\X\Project\PMSM\Demo\+task\+dataDictionary\t1_openTestBench.mĬ:\X\Project\PMSM\Demo\+task\+dataDictionary\t2_importEnums.mĬ:\X\Project\PMSM\Demo\+task\+dataDictionary\t3_partitionData.mĬ:\X\Project\PMSM\Demo\+task\+dataDictionary\t4_multipleDictionaries.mĬ:\X\Project\PMSM\Demo\+task\+mac2015\t1_openTestBench.mĬ:\X\Project\PMSM\Demo\+task\+mac2015\t2_generateCodeAndCopyToParentProject.mĬ:\X\Project\PMSM\Demo\+task\+pcgF28035\t1_openTestBench.mĬ:\X\Project\PMSM\Demo\+task\+pcgF28035\t2_generateCodeAndCopyToParentProject.m It is one I have used in my own development projects. I’m not sure I can answer the question “Why not MATLAB?”, but Peter has shared an excellent solution. Operating systems have commands with this ability, why not MATLAB ***? But you soon learn that you have to call those functions recursively in order to include the files in subfolders. You find you can do name pattern matching using the '*' character. So you read the MATLAB documentation for DIR and LS. You want to list all the files in a folder, including those in subfolders. Greg’s pick this week is Expand wildcards for files and directory names by Peter van den Biggelaar. Potential Alternative: Use Operating System Commands.Enhance GLOB function in R2016b using the new String class.How does this differ from using the DIR function in MATLAB?.