0
|
3901 Views
|
6 Replies
|
6 Total Likes
View groups...
Share
GROUPS:

How can I merge lists using Riffle and Partition, when I need a function?

Posted 10 years ago
 I've got the data, containing the values in 5 studies and the days in the first column. I am trying to create the ErrorListPlot, but I've got the problem with syntax. Needs["ErrorBarPlots`"] pathTransplant = "C:UsersMeklonownCloudRegenLabDataWeightTransplant_ weight.xlsx"; dataTransplant1Weight = Import[pathTransplant, {"Data", 1, All, 2}]; dataTransplant2Weight = Import[pathTransplant, {"Data", 1, All, 3}]; dataTransplant3Weight = Import[pathTransplant, {"Data", 1, All, 4}]; dataTransplant4Weight = Import[pathTransplant, {"Data", 1, All, 5}]; dataTransplant5Weight = Import[pathTransplant, {"Data", 1, All, 6}]; dataTransplantWeight = List[dataTransplant1Weight, dataTransplant2Weight, dataTransplant3Weight, dataTransplant4Weight, dataTransplant5Weight]; dataDay = Import[pathTransplant, {"Data", 1, All, 1}]; meanTransplant = Mean[dataTransplantWeight]; standardErrorTransplant = StandardDeviation[dataTransplantWeight]/Sqrt[Length[dataTransplantWeight]]; plotDataTransplant = Partition[Riffle[dataDay, meanTransplant], 2] plotDataTransplantErr = Partition[Riffle[plotDataTransplant, standardErrorTransplant], 2] ErrorListPlot[plotDataTransplantErr] The problem is with plotDataTransplantErr = Partition[Riffle[plotDataTransplant, standardErrorTransplant], 2] It gives me the output like this: {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}... It is practically what I need, but I cannot insert the text "ErrorBar" in it, as I need something like this for input of ErrorListPlot: {{{0., 245.6}, ErrorBar [3.9064]}, {{1., 204.8}, ErrorBar [3.33766]}, {{3., 202.6}, ErrorBar [2.65707]} This doesn't work either: ErrorListPlot[{plotDataTransplant, ErrorBar[standardErrorTransplant]}] Attachments:
6 Replies
Sort By:
Posted 10 years ago
 Dear Ivan, Sure. I'll try. However, I am sure that I can't improve on the explanations in the documentation.Slash-dot is perhaps one of the most powerful constructs in the wolfram language.In this case: expr/.{{a_, b_},c_}->{{a,b},ErrorBar[c]} could be read as the following. Take expression and apply the following rule (slash dot is the part that says "apply the following rule"). The rule is take something that has this pattern: {{1,2},3} and turn it into something that is related to the pattern: {{1,2}, ErrorBar[3]} However to use this for an arbitrary thing that matches the pattern {{_,_},_}, we will need the matched pattern to keep a placeholder for the {1,2} part and the 3 part. This is where pattern matching comes in: {{a_,b_}, c_}-> {a,b,ErrorBar[c]} so that c_ is a placeholder for the last member of your list and we get to use "c" as the result of the match on the right-hand-side of the arrow; and a_ and b_ are the placeholders for the members of the sublist. The "meaning" of a,b, and c goes away after the pattern has been used.
Posted 10 years ago
 Sounds like a dark magic) But I still have the problem. It's 1:07 here, so I should sleep for a while. Can you provide me some links to the documentation from my case? Or can you solve the current problem if you have some time. It's hard for me to understand the problem after 12 hours of hard work( plotDataTransplantErr={{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}} plotDataTransplantErr = plotDataTransplantErr /. {{a_, b_}, c_} -> {{a, b}, ErrorBar[c]} The output is abnormal: {{{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}}, ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 313.6, x}}]}}
Posted 10 years ago
 It appears that you may have already defined c previously. In that case, this will work. plotDataTransplantErr = {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}} plotDataTransplantErr = plotDataTransplantErr /. {{a_, b_}, c_} :> {{a, b}, ErrorBar[c]} The difference here is that :> replaces the -> (it has the same purpose here as how := replaces =). Sleep well, WCC
Posted 10 years ago
 Wonderful. You've helped me very much. Thanks.
Posted 10 years ago
 Hello, This is a simple solution using the slash dot Swiss Army knife: expr = {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}} expr = expr/.{{a_, b_},c_}->{{a,b},ErrorBar[c]} I hope this might help, WCC
Posted 10 years ago
 Can you express this idea more completely? I'm using Wolfram for several weeks and it's too hard for me to understand this sometimes) I'm a doctor))