Need to put results that come in a 1x3 together for easy access. Maybe into a vector?
조회 수: 1 (최근 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
댓글 수: 0
채택된 답변
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))
[~,filename,ext] = fileparts(fullFileName);
fprintf('%s%s\n', filename, ext)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!