Automation of the finding size and the number of variables which depends on that size

1 view (last 30 days)
for i=1:numDP
data.T{i}=eye(DIM);
nearest=knnsearch(data.DataTree,P(i,:),'K',K+1);
R{i}=zeros(DIM);
for j=1:K
v=P(i,:)-P(nearest(j+1),:);
V11{i}=P(i,:);
V22{i}=P(nearest(j+1),:);
v=v';
s=norm(v);
B=exp(-s^2/sigma^2)*(eye(DIM)-v*v'/norm(v'*v));
R{i}=R{i}+B;
[data.T{i},data.D{i}]=eig(R{i});
n1{i}=data.T{i}(:,1);
N2{i}=data.T{i}(:,2);
n3{i}=data.T{i}(:,3);
lambda1=max(diag(data.D{i}));
lambda3=min(diag(data.D{i}));
lambda2=data.D{i}(2,2);
'My question is for example the number of 'lambda' and 'n' depends on 'DIM'. But as you can see this code works just for DIM=3; I need to generalize that code for every dimensions and my Matlab knowledge is not enough to do as a beginner. I put example to make it clear
  2 Comments
Walter Roberson
Walter Roberson on 14 Jan 2020
Replace
n1{i}=data.T{i}(:,1);
N2{i}=data.T{i}(:,2);
n3{i}=data.T{i}(:,3);
with
c = size(data.T{i},2);
for K = 1 : c
N{c}{i} = data.T{i}(:,K);
end
... But it doesn't look like a useful memory organization to me. Why not just store all of data.T{i} ?
Zeynep Naz Kocabas
Zeynep Naz Kocabas on 21 Jan 2020
Why is not useful ? I use these variables on another code so I coded them inside data.T and just put another functions, data as a input. If it is your question?

Sign in to comment.

Accepted Answer

Mahesh Taparia
Mahesh Taparia on 8 Jan 2020
Hi
The function knnsearch can work for N dimensional data. By looking at your code, it seems the value of DIM will be the number of elements in P(i,:), if you want to increase the DIM, change the data accordingly.
  6 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!