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

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

回答(1 个)

Image Analyst
Image Analyst 2018-2-15
How about
if isequal(a, b)
% Structures a and b match completely.
end
  2 个评论
Chris Matthews
Chris Matthews 2018-2-15
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 2018-2-20
FYI - I ended up creating a if/then/elseif to Interpol the smallest of the arrays to match the length, thanks for the idea.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by