MATLAB Answers

How to change a char array into char row vectors?

28 views (last 30 days)
Hey there
I`m not sure, what format Matlab wishes to have from me. The function 'regexp' generates the error 'Error using regexp. All cells must be char row vectors.'
At the moment, my input looks like:
ListA=
72x2 char array
'BETA1'
'BETA2'
In the Matlabbatch it looks like:
BBEETTAA12
Instead of
'BETA1'
'BETA2'
How should it look like for Matlab to work? And how do I get there?
  3 Comments
Stephen Cobeldick
Stephen Cobeldick on 2 Mar 2021
S = load('matlab.mat');
S.matlabbatch{1}.spm.util.imcalc.input{:}
ans = 72x17 char array
'smwc1id000_t1.nii' 'smwc1id001_t1.nii' 'smwc1id002_t1.nii' 'smwc1id003_t1.nii' 'smwc1id004_t1.nii' 'smwc1id005_t1.nii' 'smwc1id006_t1.nii' 'smwc1id007_t1.nii' 'smwc1id008_t1.nii' 'smwc1id009_t1.nii' 'smwc1id010_t1.nii' 'smwc1id011_t1.nii' 'smwc1id012_t1.nii' 'smwc1id013_t1.nii' 'smwc1id014_t1.nii' 'smwc1id015_t1.nii' 'smwc1id016_t1.nii' 'smwc1id017_t1.nii' 'smwc1id018_t1.nii' 'smwc1id019_t1.nii' 'smwc1id020_t1.nii' 'smwc1id021_t1.nii' 'smwc1id022_t1.nii' 'smwc1id023_t1.nii' 'smwc1id024_t1.nii' 'smwc1id025_t1.nii' 'smwc1id026_t1.nii' 'smwc1id027_t1.nii' 'smwc1id028_t1.nii' 'smwc1id029_t1.nii' 'smwc1id030_t1.nii' 'smwc1id031_t1.nii' 'smwc1id032_t1.nii' 'smwc1id033_t1.nii' 'smwc1id034_t1.nii' 'smwc1id035_t1.nii' 'smwc1id036_t1.nii' 'smwc1id037_t1.nii' 'smwc1id038_t1.nii' 'smwc1id039_t1.nii' 'smwc1id040_t1.nii' 'smwc1id041_t1.nii' 'smwc1id042_t1.nii' 'smwc1id043_t1.nii' 'smwc1id044_t1.nii' 'smwc1id045_t1.nii' 'smwc1id046_t1.nii' 'smwc1id047_t1.nii' 'smwc1id048_t1.nii' 'smwc1id049_t1.nii' 'smwc1id050_t1.nii' 'smwc1id051_t1.nii' 'smwc1id052_t1.nii' 'smwc1id053_t1.nii' 'smwc1id054_t1.nii' 'smwc1id055_t1.nii' 'smwc1id056_t1.nii' 'smwc1id057_t1.nii' 'smwc1id058_t1.nii' 'smwc1id059_t1.nii' 'smwc1id060_t1.nii' 'smwc1id061_t1.nii' 'smwc1id062_t1.nii' 'smwc1id063_t1.nii' 'smwc1id064_t1.nii' 'smwc1id065_t1.nii' 'smwc1id066_t1.nii' 'smwc1id067_t1.nii' 'smwc1id068_t1.nii' 'smwc1id069_t1.nii' 'smwc1id070_t1.nii' 'smwc1id071_t1.nii'
ans = 72x56 char array
'BETA_Subject001_Condition001_Measure001_Component001.nii' 'BETA_Subject002_Condition001_Measure001_Component001.nii' 'BETA_Subject003_Condition001_Measure001_Component001.nii' 'BETA_Subject004_Condition001_Measure001_Component001.nii' 'BETA_Subject005_Condition001_Measure001_Component001.nii' 'BETA_Subject006_Condition001_Measure001_Component001.nii' 'BETA_Subject007_Condition001_Measure001_Component001.nii' 'BETA_Subject008_Condition001_Measure001_Component001.nii' 'BETA_Subject009_Condition001_Measure001_Component001.nii' 'BETA_Subject010_Condition001_Measure001_Component001.nii' 'BETA_Subject011_Condition001_Measure001_Component001.nii' 'BETA_Subject012_Condition001_Measure001_Component001.nii' 'BETA_Subject013_Condition001_Measure001_Component001.nii' 'BETA_Subject014_Condition001_Measure001_Component001.nii' 'BETA_Subject015_Condition001_Measure001_Component001.nii' 'BETA_Subject016_Condition001_Measure001_Component001.nii' 'BETA_Subject017_Condition001_Measure001_Component001.nii' 'BETA_Subject018_Condition001_Measure001_Component001.nii' 'BETA_Subject019_Condition001_Measure001_Component001.nii' 'BETA_Subject020_Condition001_Measure001_Component001.nii' 'BETA_Subject021_Condition001_Measure001_Component001.nii' 'BETA_Subject022_Condition001_Measure001_Component001.nii' 'BETA_Subject023_Condition001_Measure001_Component001.nii' 'BETA_Subject024_Condition001_Measure001_Component001.nii' 'BETA_Subject025_Condition001_Measure001_Component001.nii' 'BETA_Subject026_Condition001_Measure001_Component001.nii' 'BETA_Subject027_Condition001_Measure001_Component001.nii' 'BETA_Subject028_Condition001_Measure001_Component001.nii' 'BETA_Subject029_Condition001_Measure001_Component001.nii' 'BETA_Subject030_Condition001_Measure001_Component001.nii' 'BETA_Subject031_Condition001_Measure001_Component001.nii' 'BETA_Subject032_Condition001_Measure001_Component001.nii' 'BETA_Subject033_Condition001_Measure001_Component001.nii' 'BETA_Subject034_Condition001_Measure001_Component001.nii' 'BETA_Subject035_Condition001_Measure001_Component001.nii' 'BETA_Subject036_Condition001_Measure001_Component001.nii' 'BETA_Subject037_Condition001_Measure001_Component001.nii' 'BETA_Subject038_Condition001_Measure001_Component001.nii' 'BETA_Subject039_Condition001_Measure001_Component001.nii' 'BETA_Subject040_Condition001_Measure001_Component001.nii' 'BETA_Subject041_Condition001_Measure001_Component001.nii' 'BETA_Subject042_Condition001_Measure001_Component001.nii' 'BETA_Subject043_Condition001_Measure001_Component001.nii' 'BETA_Subject044_Condition001_Measure001_Component001.nii' 'BETA_Subject045_Condition001_Measure001_Component001.nii' 'BETA_Subject046_Condition001_Measure001_Component001.nii' 'BETA_Subject047_Condition001_Measure001_Component001.nii' 'BETA_Subject048_Condition001_Measure001_Component001.nii' 'BETA_Subject049_Condition001_Measure001_Component001.nii' 'BETA_Subject050_Condition001_Measure001_Component001.nii' 'BETA_Subject051_Condition001_Measure001_Component001.nii' 'BETA_Subject052_Condition001_Measure001_Component001.nii' 'BETA_Subject053_Condition001_Measure001_Component001.nii' 'BETA_Subject054_Condition001_Measure001_Component001.nii' 'BETA_Subject055_Condition001_Measure001_Component001.nii' 'BETA_Subject056_Condition001_Measure001_Component001.nii' 'BETA_Subject057_Condition001_Measure001_Component001.nii' 'BETA_Subject058_Condition001_Measure001_Component001.nii' 'BETA_Subject059_Condition001_Measure001_Component001.nii' 'BETA_Subject060_Condition001_Measure001_Component001.nii' 'BETA_Subject061_Condition001_Measure001_Component001.nii' 'BETA_Subject062_Condition001_Measure001_Component001.nii' 'BETA_Subject063_Condition001_Measure001_Component001.nii' 'BETA_Subject064_Condition001_Measure001_Component001.nii' 'BETA_Subject065_Condition001_Measure001_Component001.nii' 'BETA_Subject066_Condition001_Measure001_Component001.nii' 'BETA_Subject067_Condition001_Measure001_Component001.nii' 'BETA_Subject068_Condition001_Measure001_Component001.nii' 'BETA_Subject069_Condition001_Measure001_Component001.nii' 'BETA_Subject070_Condition001_Measure001_Component001.nii' 'BETA_Subject071_Condition001_Measure001_Component001.nii' 'BETA_Subject072_Condition001_Measure001_Component001.nii'
I do not see any reason why you cannot call cellstr on those character matrices. But whether this conversion or data type is appropriate for the tool/function/app that you are using depends on that tool/function/app.

Sign in to comment.

Accepted Answer

Jan
Jan on 2 Mar 2021
ListA = ['BETA1'; ...
'BETA2'];
ListAC = cellstr(ListA);
Now you can run REGEXP on the cell string.
  1 Comment
Carole Wagnon
Carole Wagnon on 2 Mar 2021
Thank you but sadly, this doesn`t work either.
Item 'Input Images', field 'val': Value must be either empty, a cellstr or a cfg_dep object.
Error using spm_jobman>fill_run_job (line 472)
No executable modules, but still unresolved dependencies or incomplete module inputs.
Error in spm_jobman (line 247)
sts = fill_run_job('run', cjob, varargin{3:end});

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!