How to interpolate a cloud of points?

Hello all,
I have an set of 2D mean values from which I would like to compute the largest values. My 2D matrix is store so:
[rows, columns, count_there] = find(store == max(store));
By plotting rows vs columns I get the following picture:
I was wondering if there is any way to interpolate these data to get something like:
and to compute the length of it.

 Accepted Answer

Matt J
Matt J on 25 Jul 2022
Edited: Matt J on 25 Jul 2022
I've no way of testing this without your row/column data, but:
[rows, columns, count_there] = find(store == max(store));
[idx,edges]=discretize(columns,20);
edgectr=conv2(edges,[1,1]/2,'valid')';
G=findgroups(idx);
rowctr=splitapply(@median,rows,G);
colctr=splitapply(@(x) x(1),edgectr(idx),G);
scatter(rows,columns); hold on
plot(rowctr, colctr,'k-o','LineWidth',3); hold off
Length=sum(vecnorm(diff([rowctr(:),edgectr(:)]),2,2))

11 Comments

Thanks for your reply Matt J. I attach the .mat for variable store.
load store
[rows, columns, count_there] = find(store == max(store));
[idx,edges]=discretize(columns,20);
edgectr=conv2(edges,[1,1]/2,'valid')';
G=findgroups(idx);
rowctr=splitapply(@median,rows,G);
colctr=splitapply(@(x) x(1),edgectr(idx),G);
scatter(rows,columns); hold on
plot(rowctr, colctr,'k-o','LineWidth',3); hold off
Length=sum(vecnorm(diff([rowctr(:),edgectr(:)]),2,2))
Length = 1.3059e+03
It workes perfectely! Thank you so much :)
Just want to ask you the last question: how to sum up the value along the black line at different length, as shown in the following picture?
It workes perfectely! Thank you so much :)
You're welcome, but please Accept click the answer to indicate so
how to sum up the value along the black line at different length
I think you would probably need to first use interparc from the File Exchange to get more row/column samples
Then you can use discretize() again, similar to the above
[idx,edges]=discretize(rows,20);
G=findgroups(idx);
rowctr=splitapply(@sum,columns,G);
colctr=splitapply(@(x) x(1),edgectr(idx),G);
Hello @Matt J,
again, thank you very much. I have implemented the following part of the code:
[rowNew columnNew] = interparc(100,rows,columns,'spline');
[idx,edges]=discretize(rowNew,20);
G=findgroups(idx);
rowctr=splitapply(@sum,columnNew,G);
colctr=splitapply(@(x) x(1),edgectr(idx),G);
But it doesn't seems clear to me if it does the right thing.
Is it doing the wrong thing? How do you know?
Because when I perform
[rowNew columnNew] = interparc(0.5,rows,columns,'spline');
it gives me an error. Furthermore I do not really understand how I can get the length of the black line at a specific spot like column 700.
Matt J
Matt J on 26 Jul 2022
Edited: Matt J on 26 Jul 2022
What is "the length of the black line at a specific spot"? Do you mean you want the length over certain intervals? What defines the interval boundaries?
Sorry if I was not clear. Till the following stage everything is ok:
now I want to sum the values of the black line at specific coulums I want to define e.g., 500, 700, 900:
basically I wanna do:
column=500 -> sum1 = 1+2
column=700 -> sum2 = 3+4
column=900 -> sum 3 = 5+6
This File Exchange file seems to do a decent job,
load store
[rows, columns, count_there] = find(store == max(store));
[idx,edges]=discretize(columns,20);
edgectr=conv2(edges,[1,1]/2,'valid')';
G=findgroups(idx);
rowctr=splitapply(@median,rows,G);
colctr=splitapply(@(x) x(1),edgectr(idx),G);
scatter(rows,columns); hold on
plot(rowctr, colctr,'k-o','LineWidth',3);
verticals=[600,700,800];
for i=1:numel(verticals)
[x0,y0]=intersections(rowctr,colctr,verticals(i)*[1,1],[0,1000]);
plot(x0,y0,'x--r');
valuesum(i)=sum(y0);
end; hold off
valuesum
valuesum = 1×3
1.0e+03 * 1.0162 1.0008 1.0144
Just tested and it is amazing! Thanks @Matt J, you helped me a lot! :)

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!