Why my MATLAB program doesn't stop?

조회 수: 5 (최근 30일)
phdcomputer Eng
phdcomputer Eng 2019년 12월 1일
댓글: Walter Roberson 2019년 12월 1일
I wrote this program in MATLAB to compute the distance between each feature with the rest of features in CNS data (attached) , but the program run for a long time and doesn't show the result.
I'll be gratefull to have your opinions about what is the reason of this problem and how can I solve It to have the output. Thanks.
clc;
clear;
close all;
tic
load CNS.mat
data=CNS;
[n,m]=size(data);
for i=1:m-1
for j=i+1:m
t5(i,j)=fHammingDist(data(:,i),data(:,j));
b5=sum(t5)/(m-1);
end
end
[B5,indB5]=sort(b5,'descend');
databs5=data(:,indB5(1:10));
databs5=[databs5,data(:,m)];
save('databs5.mat');
I defined the distance as a function (fHammingDist)
function [ fhd ] = fHammingDist( p,q )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
fhd=sum(abs(p-q));
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 12월 1일
for i=1:m-1
for j=i+1:m
t5(i,j)=fHammingDist(data(:,i),data(:,j));
b5=sum(t5)/(m-1);
end
end
Notice that you calculate b5 in each iteration of the inner for loop, overwriting the previous value completely, but you do not use the value inside the loops. There is therefore no point in calculating it inside the loops. It would make more sense to calculate it after the end of the nested loops.
You appear to be calculating the lower triangle of distances, but when you form b5 you do not fill in the upper triangle first by symmetry, so the later columns are going to be totalling fewer and fewer entries. It is not obvious that is what is desired.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Hamming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by