Changing variable names based on a string
古いコメントを表示
Hi all,
I am trying to do some basic imaging processing where I want a script to run through different ROIs on each hemisphere of the brain. Right now I have to run a script manually with each file name (RightPLIC). Is there anyway to code file names with two separate editable strings? i.e. ('hemisphere''ROItarget')
So that I don't have to manually change each line each time I run the code? In linux I typically use {$fname}, but that won't work here...
Thanks in advance for any help!
Below is an example of what I'm talking about. I want to be able to just update "right" or "M1" or "PLIC" more quickly.
% files needed to do pde tracking seedfile = [dirname, 'RightPLIC']; % seed targetfile = [dirname, 'RightM1_ACPC_DTI_space']; % target
maskfile = [dirname, 'dti.moco.bet '];
sidemaskfile = [dirname, 'right_mask']; % this will be combined with anatomical mask
% name of output file: nifti
outputfile = 'RightM1_ACPC.count';
File = 'RightM1_ACPC.count.nii.gz';
採用された回答
その他の回答 (2 件)
Ahmet Cecen
2014 年 8 月 13 日
1 投票
Use eval alongside strcat and num2str.
Joseph Cheng
2014 年 8 月 13 日
Sightly confused on what you're trying to do but here is my attempt.
STR = 'Right'; %or M1 or PLIC
% files needed to do pde tracking
seedfile = [dirname, STR, 'PLIC']; % seed
targetfile = [dirname, STR, 'M1_ACPC_DTI_space']; % target
maskfile = [dirname, 'dti.moco.bet '];
sidemaskfile = [dirname, STR, '_mask']; % this will be combined with anatomical mask
% name of output file: nifti
outputfile = [STR, 'M1_ACPC.count'];
File = [STR, 'M1_ACPC.count.nii.gz';
Since these are all String arrays you can concatenate them with each other like you were already doing. Since i couldn't figure out based on your example of the target file and output file having RightM1 i left it in there. you could possibly edit this with a switch/case statement so depending on what the edit string is you can get two string substitution variables to make 'RightM1' instead of just right.
%air coding so pardon any errors
type = 'Right'
switch type
case 'right'
STR1 = 'Right'
STR2 = 'RightM1'
case 'M1'
STR1 = _)___
STR2=_____
case 'PLIC'
end
same stuff above but use STR1 or STR2 depending on which one fits.
Additionally if your files are named in a particular way you could write this to do it automatically and detect which strings to update.
カテゴリ
ヘルプ センター および File Exchange で Image Sequences and Batch Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!