Including the filename in a matrix with many other values

1 view (last 30 days)
New to matlab. I have a program that opens many images and spits back values for each variable; each line represents a new image and has 9 variables seperated by a space. I can't find a way to get it to tell me which file it has open to give me those values. Can anyone help?

Accepted Answer

Walter Roberson
Walter Roberson on 18 Jan 2016
Use a cell array if you need it as a variable. For example,
for K = 1 : 10
filename = sprintf('ghoatkidney_%02d.bmp', K);
thisimage = imread(filename);
nine_stats = calculate_some_statistics(thisimage);
nine_stats_cell = num2cell(nine_stats);
outputs{K,1} = filename;
outputs{K,2:10} = nine_stats_cell{:};
end
  2 Comments
Troy Steiner
Troy Steiner on 18 Jan 2016
Really new to matlab, sorry. so here are the 9 variables:
topoutward = [topleftoutward toprightoutward];
bottominward = [bottomleftinward bottomrightinward];
topinward = [topleftinward toprightinward];
bottomoutward = [bottomleftoutward bottomrightoutward];
inwardmean = mean(mean(imageedit_inward));
outwardmean = mean(mean(imageedit_outward));
topinwardmean = mean(mean(topinward));
bottominwardmean = mean(mean(bottominward));
topoutwardmean = mean(mean(topoutward));
bottomoutwardmean = mean(mean(bottomoutward));
fullratio = inwardmean/outwardmean;
topratio = topinwardmean/topoutwardmean;
bottomratio = bottominwardmean/bottomoutwardmean;
Are you suggesting I need to add this in to the "nine_stats" variable? Would the top line read filename = sprintf('*.bmp', K)?
Walter Roberson
Walter Roberson on 19 Jan 2016
nine_stats = [inwardmean, outwardmean, topinwardmean, bottominwardmean, topoutwardmean, bottomoutwardmean, fullratio, topratio, bottomratio];
and
filename = sprintf('%d.bmp', K);
if the file names are to be 1.bmp 2.bmp 3.bmp ... 10.bmp 11.bmp and so on.
If the file names are to be extracted from a directory then see

Sign in to comment.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!