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)

回答(1 个)

Walter Roberson
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.

类别

Help CenterFile 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!

Translated by