필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Chris Matthews
Chris Matthews 2018년 2월 15일
댓글: Chris Matthews 2018년 2월 20일
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에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by