MATLAB Answers

Reformating cell array of chars

1 view (last 30 days)
MiauMiau
MiauMiau on 25 Mar 2017
Edited: Jan on 25 Mar 2017
Hi
What I want is the following: I have 4D-files, I want to extract the names of the 3d slices in these files. Say I have a 4D file, which consists of three such slices, I would like to have the names of these slices as follows:
a = {
'/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,1'
'/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,2'
'/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,3'}
This gives me here a 3x1 cell. If there are many such slices, doing this manually is of course quite difficult. There is a function which recursively finds the name of the slices of 4D volumes in a folder, however it gives back a char array, e.g.:
/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,1
/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,2
/myComputer/10_22022017_0833036_2_1_wipepi168V4.nii,3
My question: How can I convert this char array in the format above, e.g. into a 3x1 cell containing the names? It should be as automated as possible (sometimes there might be 200 slices, sometimes 300 etc.)
Thanks

Answers (1)

Jan
Jan on 25 Mar 2017
Edited: Jan on 25 Mar 2017
If the function replies a char array, simply use:
a = cellstr(c)
I guess, that it is easy to write a function, which finds the file names:
DirList = dir('/myComputer/*.nii,*');
FileList = fullfile('/myComputer/', {DirList.name});

Community Treasure Hunt

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

Start Hunting!