MATLAB Answers

0

How to convert Contour subscripts to indices

Asked by Kathleen DiNapoli on 26 Nov 2019 at 20:08
Latest activity Answered by Kathleen DiNapoli on 5 Dec 2019 at 0:00
Hello,
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Kathleen DiNapoli on 5 Dec 2019 at 0:00
 Accepted Answer

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.

  0 Comments

Sign in to comment.