5
$\begingroup$

I have a list of 3d coordinates.

data = {{1., 2., 3.}, {2., 3., 4.}, {4., 5., 6.}, {6., 7., 8.}, {8., 
9., 10.}};
Dimensions[data]
data[[All, 2]] = data[[All, 2]]*0;
data
Dimensions[data]
data = DeleteCases[data, 0., 2]
Dimensions[data]

{5, 3}
{{1., 0., 3.}, {2., 0., 4.}, {4., 0., 6.}, {6., 0., 8.}, {8., 0., 10.}}
{5, 3}
{{1., 3.}, {2., 4.}, {4., 6.}, {6., 8.}, {8., 10.}}
{5, 2}

The code abode does as expected it reduces the dimensions from {5,3}->{5,2} I tried the same code on a larger array, dimensions then go from {11698,3} -> {11698}. The elements are still {x,z} if one calls LargeArray[[1]] one get a list of two elements. However mathematica treats its as on entity. This causes the data to not be interpreted right in a ListPLot call. Any thought on why this is happening?

$\endgroup$
  • $\begingroup$ I'm guessing that the array became ragged and not all sublists have the same length any more. E.g., Dimensions[{{1, 2}, {1}, {1, 3}}] === {3}. Try Counts[Length /@ LargeArray] and see how many different lengths there are in your array. $\endgroup$ – Sjoerd Smit Sep 12 '18 at 14:31
  • $\begingroup$ That actually might be it, I didnt take into account that if either x or z is 0. it get deleted creating list with just one or zero elements. $\endgroup$ – Giovanni Baez Sep 12 '18 at 14:37
5
$\begingroup$

I take it you are trying to plot the (x,z) coordinates against one another?

It is safer to delete the (y) coordinates than replacing them with zeros and deleting zeros. If there are any other zeros in the data you will get undesired results. I suspect this is the case, since your data's new shape is only {116908} (meaning not all entries are the same length).

Instead, you could take only the first and last column like:

data[[All, {1, 3}]]
$\endgroup$
  • 2
    $\begingroup$ That was exactly what was happening. Thanks Tyler. $\endgroup$ – Giovanni Baez Sep 12 '18 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.