MATLAB Answers

How to convert Contour subscripts to indices

1 view (last 30 days)
I am trying to get the linear indices of subscripts that are derived from a contour plot.
I am first making the contour using:
[membranePoints1] = contour(1:matSize(2), 1:matSize(1), membranePotentialFunction1, [0 0 0], 'k');
Giving a plot that looks like this:
Then using a script from file exchange to extract out the x, y coordinates I get an array of 2Xnumber of rows :
[xc,yc] = C2xyz(membranePoints1);
I then am trying to convert these coordinates to a linear index for following computations using the function:
schemeData1.indexValues1 = sub2ind([matSize(2) matSize(1)], xc{1}, yc{1});
But if I convert these indicies back to xy values using
[ivR1, ivR2] = ind2sub(matSize, schemeData1.indexValues1);
My plot looks like this:
Is there any advice as to what may be happening?
Thank you

Accepted Answer

Kathleen DiNapoli
Kathleen DiNapoli on 5 Dec 2019
Just following up to close this issue. I'm posting what I did in case anyone else has this issue in the future and comes looking. The problem is that the contour function gives non integer multiples of the points to smooth the line but index2sub only can deal with integers. I took the floor of the x,y coordinates of the contour and then you are able to easily convert between subscript and index terms.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!