필터 지우기
필터 지우기

How can I create an updating variable for a user input foler name?

조회 수: 1 (최근 30일)
Adam Takeshita
Adam Takeshita 2023년 5월 25일
답변: Walter Roberson 2023년 5월 25일
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에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by