Automation of the finding size and the number of variables which depends on that size
1 view (last 30 days)
Show older comments
Zeynep Naz Kocabas
on 4 Jan 2020
Commented: Zeynep Naz Kocabas
on 21 Jan 2020
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
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} ?
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!