Effacer les filtres
Effacer les filtres

How to perform arithmetic operation in pdist?

2 vues (au cours des 30 derniers jours)
Asyran Abdullah
Asyran Abdullah le 30 Sep 2018
Commenté : Image Analyst le 2 Oct 2018
Hi, i need some advice for solving the error of using squareform,
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in mapmulti (line 234)
distAllTier1(i,j) = squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] ));
And the code as follow:
for i = 1:1:numNodes
for j = indPCHTier1 %indPCHTier1 = 1 3 5 7 13 18 21 = j(7)
if node(i).tier == 1
if i == j
distAllTier1(i,j) = NaN;
else
distAllTier1(i,j) = squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] ));
end
end
end
end
Thanks :D
  3 commentaires
Asyran Abdullah
Asyran Abdullah le 30 Sep 2018

The complete code is too long, here i simplify the value of code.

numNodes  = 100
indPCHTier1 =  1     3     5     7    13    18    21
squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] )) = have Columns 1 through 25 with random number. 

eg:

Then, how can i put the value of "squareform (pdist)" into distAllTier1(i,j) ?

Thanks.

Asyran Abdullah
Asyran Abdullah le 30 Sep 2018
A1  =  pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] );
distAllTier1(i,j)  = squareform(A1);

I try to make something different. Still error.

Here is previous code:

distAllTier1(i,j) = sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2); 

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 1 Oct 2018
            distAllTier1{i,j}   = squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] ));
  4 commentaires
Asyran Abdullah
Asyran Abdullah le 1 Oct 2018

Actually, the distAllTier1 came from this line:

distAllTier1 = zeros(numNodes,numPCHTier1);

which numNodes=100 and numPCHTier1=7. Then distAllTier1 result will be 0 in 100 lines as follow:

>> length(distAllTier1)
ans =
     100

I just want to make the,

squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] ))

result, save in distAllTier1(i,j). How can i do it? Any advice?

Walter Roberson
Walter Roberson le 1 Oct 2018
distAllTier1 = cell(numNodes,numPCHTier1);

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 1 Oct 2018
Why not just use pdist2() and not worry about squareform()?
I always use pdist2() and never use pdist().
  6 commentaires
Asyran Abdullah
Asyran Abdullah le 2 Oct 2018
Modifié(e) : Asyran Abdullah le 2 Oct 2018
This is a original code that use single input:
distAllTier1(i,j) = sqrt((node(i).x - baseStation.x).^2 + (node(i).y - baseStation.y).^2);
I and J use to find the distance between them. I modify the code to make it able to operate in multiple vector. Then is use this,
distAllTier1(i,j) = squareform (pdist([node(j).x - node(i).x] + [node(i).y - node(j).y] ));
I dont know either in multiple vector it need to find distance between i & j or not.
Image Analyst
Image Analyst le 2 Oct 2018
Make it easy to help you. Attach your node variable in a .mat file.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by