How can I create an updating variable for a user input foler name?
2 次查看(过去 30 天)
显示 更早的评论
The fname variable will be changed manually in the first line, how can I have the 5th line automatically update the file name so I don't have to change it as well? Thank you in advance!
fname='Adam2.tif';
importfile(fname);
scan_loc=800
binsize=50
blah=Adam2(3:end,scan_loc-binsize/2:scan_loc+binsize/2)
0 个评论
回答(1 个)
Walter Roberson
2023-5-25
scan_loc = 800;
binsize = 50;
filenums = [2, 7, 11:13]; %eg. you want Adam2, Adam7, Adam11, Adam12, Adam13
numfiles = length(filenums);
blahs = cell(numfiles, 1);
for K = 1 : numfiles
fname = "Adam" + filenums(K) + ".tif";
im = imread(fname);
blah = im(3:end, scan_loc-binsize/2:scan_loc+binsize/2, :);
blahs{K} = blah;
end
This will not give you variables named the same thing as your files; we recommend against dynamically creating variable names.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!