Performing pdist2 in a for-loop with varying lengths of arrays

3 visualizaciones (últimos 30 días)
Chris Matthews
Chris Matthews el 15 de Feb. de 2018
Comentada: Chris Matthews el 20 de Feb. de 2018
Hi,
I have a for loop that calls a .mat file one by one from a folder and compares it to a separate baseline .mat file. My code (has been modified for readability) goes something like this:
a = load ('H:\Actor 01 Normal Intensity Only\Actor01.mat
%baseline .mat file
%then loads the baseline data into array
neutralRMSdata = a.RMSFramesMat;
for k = 1:length(myFiles)
%runs through the folder
%file information
baseFileName = myFiles(k).name;
FileName=[baseFileName,num2str(baseFileName)] ;
fullFileName = fullfile(myfolder, baseFileName);
%loads the data for the file that I want to compare to baseline neutralRMS
b = load (fullFileName);
%puts it into an array, size varies as the loop runs through the 32 files!!!
FileRMSdata = b.RMSFramesMat;
EucDist = pdist2(neutralRMSdata, FileRMSdata, 'hamming');
%this doesn't work because the size of FileRMSdata isn't the same as the neutralRMS array,
%and the size of the FileRMSdata changes with each loop iteration
end
So I need to be able to compare the length of the FileRMS each loop iteration with the length of NeutralRMS, and then either
a) pad the end of the shorter file with NaN values in order to complete the pdist2.
b) interpolate the shorter of the two arrays and then I should be able to run pdist2
Any help welcome!! Thanks, Chris
Any ideas?

Respuestas (1)

Image Analyst
Image Analyst el 15 de Feb. de 2018
How about
if isequal(a, b)
% Structures a and b match completely.
end
  2 comentarios
Chris Matthews
Chris Matthews el 15 de Feb. de 2018
Thanks for the answer, i need though, to be able to change the size of the smaller matrix so I can compare each value within the matrix to the neutral matrix. Any idea how I can do this as part of the for loop?
Like:
Take file matrix
Determine length of file matrix
Compare to length of neutral matrix
Either extend neutral matrix or file matrix to same size as other with NaN
Continue with loop
Chris Matthews
Chris Matthews el 20 de Feb. de 2018
FYI - I ended up creating a if/then/elseif to Interpol the smallest of the arrays to match the length, thanks for the idea.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Statistics and Machine Learning Toolbox 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