Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Adam Takeshita
Adam Takeshita am 25 Mai 2023
Beantwortet: Walter Roberson am 25 Mai 2023
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)

Antworten (1)

Walter Roberson
Walter Roberson am 25 Mai 2023
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.

Community Treasure Hunt

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

Start Hunting!

Translated by