# computation on each column in matrix - projecting the Matrix onto a plane

2 views (last 30 days)
I have this matrix R which has 10095 columns and three rows - meaning each column represents a coordinate x,y,z
I am wondering how I can operate on each column and save the result in a new matrix?
Here is my projection code, but p1 (the point to be projected) is just one of my 10095 points and I can not go repeating this by hand!
p0 = [0; 0; 0] %the point in my new plane, the one I am gonna project onto
N = [1,2,3]; %Normal to the plane which has the point p0
p1 = [1,90,0] %Just one of the points from the matrix R I used, but now I need p1 to be general for all the points
point_project = p1 + dot(p1-p0, N) * N; %here p1 would be column 1 then column 2 then column 3.... in my matrix R

Ameer Hamza on 19 Oct 2020
Edited: Ameer Hamza on 19 Oct 2020
Try this
p0 = [0; 0; 0]; %the point in my new plane, the one I am gonna project onto
N = [1,2,3].'; %Normal to the plane which has the point p0
p1 = rand(3, 10095); %Just one of the points from the matrix R I used, but now I need p1 to be general for all the points
point_project = p1 + dot(p1-p0, repmat(N, 1, 10095)) .* N; %here p1 would be column 1 then column 2 then column 3.... in my matrix R
I have changed N to a column vector.