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

1 visualización (últimos 30 días)
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 comentarios
Walter Roberson
Walter Roberson el 14 de En. de 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 el 21 de En. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Mahesh Taparia
Mahesh Taparia el 8 de En. de 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 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by