An alternative to (%%…%) (k times)how to print stack trace when TimeConstrained times outAlternative to using global variables in functions?Alternative to NotebookLocate or NotebookFindManipulate executes expressions multiple timesNeed to run evaluation 2 timesWhy does `Times` evaluate within `Hold` when doing replacement?How to evaluate a notebook several times with distinct parameters?How do I make $0 times (mathsfanything)=0$?How to Open, Evaluate and Close the same Notebook 100 times in a row?Evaluate calls my function multiple times when the function generates an error

Does the 'java' command compile Java programs?

Isn't the detector always measuring, and thus always collapsing the state?

Is there a way to remove Smite from a weapon?

Confusion regarding control system of Mars Rover?

Principled construction of the quaternions

Why do Russians sometimes spell "жирный" (fatty) as "жырный"?

What is the difference between increasing volume and increasing gain?

Airport Security - advanced check, 4th amendment breach

Decision Variable Value from a Set (Gurobi)

If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?

Wondering why they used ultrafast diodes in a 50 or 60Hz bridge?

Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?

Is spot metering just an EV compensation?

Caro-Kann c4-c5 push

How to level a picture frame hung on a single nail?

Re-entering the UK after overstaying in 2008

Why does it seem the best way to make a living is to invest in real estate?

Everyone Gets a Window Seat

Looking for circuit board material that can be dissolved

Would a horse be sufficient buffer to prevent injury when falling from a great height?

Parent asking for money after moving out

Why such a singular place for bird watching?

Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails

French license plates



An alternative to (%%…%) (k times)


how to print stack trace when TimeConstrained times outAlternative to using global variables in functions?Alternative to NotebookLocate or NotebookFindManipulate executes expressions multiple timesNeed to run evaluation 2 timesWhy does `Times` evaluate within `Hold` when doing replacement?How to evaluate a notebook several times with distinct parameters?How do I make $0 times (mathsfanything)=0$?How to Open, Evaluate and Close the same Notebook 100 times in a row?Evaluate calls my function multiple times when the function generates an error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;

.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;








2












$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
Sin[%], Sin[o1]
Cos[%%], Cos[o2]
Tan[%%%], Tan[o3]
Sin[2 %%%%], Sin[2 o4]
Cos[2 %%%%%], Cos[2 o5]
Tan[2 %%%%%%], Tan[2 o6]

0.523599
0.5, 0.5
0.866025, 0.866025
0.57735, 0.57735
0.866025, 0.866025
0.5, 0.5
1.73205, 1.73205









share|improve this question









$endgroup$









  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    8 hours ago







  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    8 hours ago











  • $begingroup$
    Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    8 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    6 hours ago


















2












$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
Sin[%], Sin[o1]
Cos[%%], Cos[o2]
Tan[%%%], Tan[o3]
Sin[2 %%%%], Sin[2 o4]
Cos[2 %%%%%], Cos[2 o5]
Tan[2 %%%%%%], Tan[2 o6]

0.523599
0.5, 0.5
0.866025, 0.866025
0.57735, 0.57735
0.866025, 0.866025
0.5, 0.5
1.73205, 1.73205









share|improve this question









$endgroup$









  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    8 hours ago







  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    8 hours ago











  • $begingroup$
    Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    8 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    6 hours ago














2












2








2





$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
Sin[%], Sin[o1]
Cos[%%], Cos[o2]
Tan[%%%], Tan[o3]
Sin[2 %%%%], Sin[2 o4]
Cos[2 %%%%%], Cos[2 o5]
Tan[2 %%%%%%], Tan[2 o6]

0.523599
0.5, 0.5
0.866025, 0.866025
0.57735, 0.57735
0.866025, 0.866025
0.5, 0.5
1.73205, 1.73205









share|improve this question









$endgroup$




Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
Sin[%], Sin[o1]
Cos[%%], Cos[o2]
Tan[%%%], Tan[o3]
Sin[2 %%%%], Sin[2 o4]
Cos[2 %%%%%], Cos[2 o5]
Tan[2 %%%%%%], Tan[2 o6]

0.523599
0.5, 0.5
0.866025, 0.866025
0.57735, 0.57735
0.866025, 0.866025
0.5, 0.5
1.73205, 1.73205






evaluation notebooks editing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









CaioCaio

364 bronze badges




364 bronze badges










  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    8 hours ago







  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    8 hours ago











  • $begingroup$
    Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    8 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    6 hours ago













  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    8 hours ago







  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    8 hours ago











  • $begingroup$
    Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    8 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    6 hours ago








5




5




$begingroup$
Just use Out. See the "Details" section.
$endgroup$
– Alan
8 hours ago





$begingroup$
Just use Out. See the "Details" section.
$endgroup$
– Alan
8 hours ago





3




3




$begingroup$
As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
$endgroup$
– Michael E2
8 hours ago





$begingroup$
As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
$endgroup$
– Michael E2
8 hours ago













$begingroup$
Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
$endgroup$
– LouisB
8 hours ago




$begingroup$
Maybe try With[ foo = Pi/6 , Sin[ foo ], Sin[ o1 ], ... ] and use Column to arrange the output.
$endgroup$
– LouisB
8 hours ago












$begingroup$
Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
$endgroup$
– Caio
6 hours ago





$begingroup$
Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
$endgroup$
– Caio
6 hours ago











1 Answer
1






active

oldest

votes


















5














$begingroup$

% is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




Out[-k] is equivalent to %%...% (k times).




One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



ClearSystemCache[]
Range[-10^6, 10^6]~Complement~0 // AbsoluteTiming;
Join @@ -Reverse@#, # &@Range[10^6] // AbsoluteTiming;
Out[-1, -2][[;; , 1]]
SameQ @@ Out[-1, -2 - 1][[;; , 2]]



0.0201598, 0.0370587



True




Or maybe a more clear example



a;
b;
Out[-1, -2]



b, a







share|improve this answer









$endgroup$
















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206864%2fan-alternative-to-k-times%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    $begingroup$

    % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




    Out[-k] is equivalent to %%...% (k times).




    One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



    ClearSystemCache[]
    Range[-10^6, 10^6]~Complement~0 // AbsoluteTiming;
    Join @@ -Reverse@#, # &@Range[10^6] // AbsoluteTiming;
    Out[-1, -2][[;; , 1]]
    SameQ @@ Out[-1, -2 - 1][[;; , 2]]



    0.0201598, 0.0370587



    True




    Or maybe a more clear example



    a;
    b;
    Out[-1, -2]



    b, a







    share|improve this answer









    $endgroup$



















      5














      $begingroup$

      % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




      Out[-k] is equivalent to %%...% (k times).




      One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



      ClearSystemCache[]
      Range[-10^6, 10^6]~Complement~0 // AbsoluteTiming;
      Join @@ -Reverse@#, # &@Range[10^6] // AbsoluteTiming;
      Out[-1, -2][[;; , 1]]
      SameQ @@ Out[-1, -2 - 1][[;; , 2]]



      0.0201598, 0.0370587



      True




      Or maybe a more clear example



      a;
      b;
      Out[-1, -2]



      b, a







      share|improve this answer









      $endgroup$

















        5














        5










        5







        $begingroup$

        % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




        Out[-k] is equivalent to %%...% (k times).




        One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



        ClearSystemCache[]
        Range[-10^6, 10^6]~Complement~0 // AbsoluteTiming;
        Join @@ -Reverse@#, # &@Range[10^6] // AbsoluteTiming;
        Out[-1, -2][[;; , 1]]
        SameQ @@ Out[-1, -2 - 1][[;; , 2]]



        0.0201598, 0.0370587



        True




        Or maybe a more clear example



        a;
        b;
        Out[-1, -2]



        b, a







        share|improve this answer









        $endgroup$



        % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




        Out[-k] is equivalent to %%...% (k times).




        One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



        ClearSystemCache[]
        Range[-10^6, 10^6]~Complement~0 // AbsoluteTiming;
        Join @@ -Reverse@#, # &@Range[10^6] // AbsoluteTiming;
        Out[-1, -2][[;; , 1]]
        SameQ @@ Out[-1, -2 - 1][[;; , 2]]



        0.0201598, 0.0370587



        True




        Or maybe a more clear example



        a;
        b;
        Out[-1, -2]



        b, a








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        That Gravity GuyThat Gravity Guy

        2,3911 gold badge6 silver badges15 bronze badges




        2,3911 gold badge6 silver badges15 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206864%2fan-alternative-to-k-times%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單