Need to put results that come in a 1x3 together for easy access. Maybe into a vector?
1 view (last 30 days)
Show older comments
So I'm working on getting RGB values that come as X Y Z. I run this loop and get the results but I'd like to have them together in a vector so I can easily send them to excel. I'm assuming I need to use some kind of loop but I can't get it to work, I think since it comes with the three values. Also, bonus but unimportant question. Using %s/n to display the filenames and such, but I'd like if it could display only the filename instead of the full source (C:/Users/blah/blah/blah).
Here is the code:
% Specify the folder where the files live.
myFolder = 'C:\Users\Jamil\Desktop\WORK\Cuttlefish\Experiments\Cuttle Experiments\Developing Chromatophores for MVA\Chromatophore 3 Top Left Noseish of top left kind of smiley\Enhanced Contrast';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.tif'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
a = mean(reshape(imageArray, [], 3))
end
I'm assuming this is the part of interest
imageArray = imread(fullFileName);
a = mean(reshape(imageArray, [], 3))
end
0 Comments
Accepted Answer
Star Strider
on 8 May 2018
Since ‘a’ will always have 3 columns (from your reshape call), but may have different row lengths, I would save it as a cell array:
a{k} = mean(reshape(imageArray, [], 3))
[~,filename,ext] = fileparts(fullFileName);
fprintf('%s%s\n', filename, ext)
2 Comments
More Answers (0)
See Also
Categories
Find more on Structures 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!