Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 8 de Mayo de 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))
For the file name, use the fileparts (link) function. For example:
[~,filename,ext] = fileparts(fullFileName);
fprintf('%s%s\n', filename, ext)
  2 comentarios
Jamil Wanis
Jamil Wanis el 8 de Mayo de 2018
Amazing, worked perfectly. Thank you so much. I tried using a(x) but now I see the issue. I appreciate the help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by