필터 지우기
필터 지우기

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)
  댓글 수: 2
Jamil Wanis
Jamil Wanis 2018년 5월 8일
Amazing, worked perfectly. Thank you so much. I tried using a(x) but now I see the issue. I appreciate the help.

댓글을 달려면 로그인하십시오.

추가 답변 (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