Hello everyone

I just encountered two problems at once. First of all I want to calculate the sum of a 3d-matrix with respect to one dimension! Unfortunately the sum only seems to work with 2d-matrices.

The second problem is a mathematical problem. I am pretty sure that it's possible to change a n x m x 1 matrix to an n x m x p matrix by multiplying it with something else. Since I could not figure it out I used a loop, but I guess that's not very effective if I want to use this part multiple times

My program is as follows:

syms a b c d e f

pos=[a b;c d;e f]; % x,y

[np,nd]=size(pos); %number of points, number of dimensions

for k1=1:np; pos1(k1,:,:)=pos'; pos2(:,:,k1)=pos; end % OPTIMIZE !!

(pos1-pos2).^2 % here it is a 3x2x3 matrix

sum( (pos1-pos2).^2 ,2) % here it is a 3x1 vector

I would really appreciate your help ..

thanks in advance

stefan

(the whole point of this program is to calculate the distances between all points given in pos)

---------

What makes you say that? sum(X,3) should work fine

It cna be done this way

[I,J]=ndgrid(1:np,1:np);

Distances=norm( pos(I(:),:)-pos(J(:),:) )

1. How to manipulate matrix dimension (2D->3D and 3D->2D)?

2. Creating 2D RGB matrix from 3D RGB matrix(Color Image Representaion)

3. convert long 2D matrix into a 3D matrix

4. How to read in 2D matrix from a 3D matrix in Simulink?

5. Indexing a 2D matrix into a 3D matrix help

6. Take a 2D slice from a 3D-matrix

7. Convert 2 Dim Decimal Matrix to Binary Matrix and reverse

8. how to break a big column matrix into 2d matrix?

9. reorder a 2d matrix based on [a b]=sort of a different matrix

10. Creating 3D RGB matrix from 2D image values

11. assign 2D array from slice of 3D matrix

12. multiply 3D matrix by 1D vector resulting in 4D matrix

14. Question about viewmtx and projection matrix from 3D to 2D

15. 3D --> 2D mapping using 3x4 projection matrices

3 post • Page:**1** of **1**