Need to put results that come in a 1x3 together for easy access. Maybe into a vector?

2 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2018-5-8
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))
For the file name, use the fileparts (link) function. For example:
[~,filename,ext] = fileparts(fullFileName);
fprintf('%s%s\n', filename, ext)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by