Calculating maximum distance from 3 different points

9 views (last 30 days)
So I generate a test array and three points (Q) using command window:
pixels = zeros(1,3,3,'uint8');
pixels(:,:,1) = [54,50,45];
pixels(:,:,2) = [48,52,43];
pixels(:,:,3) = [50,41,47];
Q1 = [54,48,50];
Q2 = [50,52,41];
Q3 = [45,43,47];
I use my first function which calculates the median of pixels and this is put into an array e.g P=[54,55,76].
I use my second function to calculate the distance between pixels, which is:
[squaredDistance] = PixelDistance(P,Q)
However, I need to subtract Q1 from P as well as Q2 from P and Q3 from P using squared distance formula e.g
Q1 = [54,48,50]
[squaredDistance] = PixelDistance(P,Q1)
The question is how do I subtract Q1,Q2, and Q3 given that the function only works with Q?
Sara Foster
Sara Foster on 8 Sep 2019
They were just randomly generated numbers, and I could pass all three in, but I was wondering if there was a shorter way?

Sign in to comment.

Answers (1)

Jyotish Kumar
Jyotish Kumar on 12 Nov 2019
Edited: Jyotish Kumar on 12 Nov 2019
If the code is vectorizable, PixelDistance(P, [Q1;Q2;Q3]) should give the desired output.
If not, to achieve a shorter way to compute the distances w.r.t all Qs at once, the code needs to be vectorized.


Find more on Multidimensional 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!

Translated by