# sorting out the coordinate and respective solution values for plotting

I want to plot for coordinates and corresponding solution values below.

 coor = {0.,6000., 2000., 4000., 8000., 10000., 6000., 12000., 8000., 10000.}
ϕvalue = {{1.}, {0.178533}, {1.0287}, {0.709987}, {}, {},
{0.138083}, {0.00703084}, {-0.059974}, {0.01218}}



For that I have removed the empty solution ({}) values from the ϕvalue vector by using DeleteCases and Flatten. But unfortunately I could not delete or remove the respective coordinate values. Because of that I am not getting the corresponding ϕvalue for the coordinate which are repeating and also solution ϕvalue values for repeating coordinates are getting interchanged in between.

See below output which is not in correct pair.

{{0.,1.}, {0.,1.}, {2000.,1.0287}, {4000.,0.709987}, {6000.,-0.059974},
{6000.,0.178533}, {8000.,0.138083}, {10000.,0.00703084}, {12000.,0.01218}}


My question is how to skip the every 5th and 6th coordinate value and also the cooresponding empty solution value?

I have already checked the Drop and Exclusion commands, but could not make them work.

(Debug) Out[18]= {0., 6000., 2000., 4000., 0., 8000., 10000., 6000., 12000., 8000., 10000.}

(Debug) Out[20]= {{1.}, {0.178533}, {1.0287}, {0.709987}, {1.}, {}, {},{0.138083}, {0.00703084}, {-0.059974}, {0.01218}}

(Debug) Out[22]= {{1.}, {0.178533}, {1.0287}, {0.709987}, {1.}, {}, {},{0.138083}, {0.00703084}, {-0.059974}, {0.01218}}

y = Flatten[p]

(Debug) Out[23]= {1., 0.178533, 1.0287, 0.709987, 1., 0.138083, 0.00703084, -0.059974, 0.01218}


cϕ = SortBy[First] @ Select[Length@# == 2 &]@Join[List /@ coor, ϕvalue, 2];

ListLinePlot[cϕ]


Alternatively,

cϕ2 = SortBy[First][Flatten /@ Select[FreeQ[{}]]@Transpose[{coor, ϕvalue}]];

cϕ3 = SortBy[First][Flatten /@ DeleteCases[{_, {}}]@Transpose[{coor, ϕvalue}]];

cϕ == cϕ2 == cϕ3

 True

• SortBy[First] @ Select[Length@# == 2 &]@Join[List /@ coor, ϕvalue, 2] could you please explain the syntax from Select[]? Commented Nov 15, 2020 at 17:32
• @user75507, SortBy[First] @ Select[Length@# == 2 &]@Join[List /@ coor, ϕvalue, 2] is an alternative way to write SortBy[ Select[Join[List /@ coor, ϕvalue, 2],Length@# == 2 &], First]. The part Join[List /@ coor, ϕvalue, 2] gives a list of lists; the elements that correspond to {} in ϕvalue have length 1 and the ones we want have length 2; hence we use the selector function Length[#] ==2&.
– kglr
Commented Nov 15, 2020 at 18:52