Group Abstract Group Abstract

Message Boards Message Boards

0
|
22.6K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Remove curly brackets from table?

i have a data of the form of list given below

sol={{0., {1.}}, {0.5, {0.706352}}, {1., {0.536753}}, {1.5, {0.42632}},
{2., {0.348796}}, {2.5, {0.291456}}, {3., {0.247375}}, {3.5, {0.212457}}, 
{4., {0.18413}}, {4.5, {0.160696}}, {5., {0.140989}}, {5.5, {0.124187}}, 
{6., {0.109689}}, {6.5, {0.0970502}}, {7., {0.085931}}, {7.5, {0.0760704}}, 
{8., {0.0672633}}, {8.5, {0.059347}}, {9., {0.0521905}}, {9.5, {0.0456872}},
{10., {0.0397498}}, {10.5, {0.0343056}}, {11., {0.0292943}}, {11.5, {0.0246648}},
{12., {0.020374}}};

I want to export it some plotting software to plot it. it consist of a pair with first term as x-coordinate and second as y-coordinate. But there is a extra bracket with the y-coordinate which don't let it plot in the plotting software. I want to remove this bracket from the y-coordinate term. For example the first two pair of the data are {0., {1.}}, {0.5, {0.706352}}. I want them to be like {0., 1.}, {0.5,0.706352} and all other terms. I tried to use the Flatten command but it fails in my case as it does not create the list like i want. Please suggest any other way or command so that i can get the data in the right form to get it plot in the plotting software.

POSTED BY: adnan saeed butt
5 Replies
Posted 9 years ago

Hi Adnan,

Would the following do the trick?

sol /. {a_, {b_}} -> {a, b}

or

Partition[Flatten[sol], 2]

Wilson

POSTED BY: Wilson Kan
Posted 9 years ago
sol2 = sol /. {x_, {y_}} -> {x, y};

ListPlot[sol2]

enter image description here

POSTED BY: David Keith

After your command, execute:

sol = Flatten /@ sol

or

sol[[All, 2]] = sol[[All, 2, 1]];
sol
POSTED BY: Sander Huisman

Try

Partition[Flatten[sol], 2]
POSTED BY: Hans Dolhaine

This works, but is very sensitive to errors; if for some reason one of the entries has an odd number of elements, you will shift everything... take caution ;)

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard