How to store values in an array?












1
















How to store a calculated value in array?




zz(1) = ( xx(1) + yy(1) )/2




fpevalzz(counter){(xx(counter)+yy(counter))/2} NOT working




documentclass{beamer}
usepackage{siunitx,amsmath}
usepackage{xparse,xfp}

ExplSyntaxOn
NewDocumentCommand{newarray}{m}
{
seq_new:c { l_hafid_array_#1_seq }
cs_new:cpn { #1 } ##1
{
seq_item:cn { l_hafid_array_#1_seq } { ##1 }
}
}
NewDocumentCommand{readarray}{mm}
{
seq_set_split:cnn { l_hafid_array_#1_seq } { & } { #2 }
}
cs_generate_variant:Nn seq_set_split:Nnn { c }

NewExpandableDocumentCommand{sumarray}{O{15}m}
{
fp_eval:n { round( seq_use:cn { l_hafid_array_#2_seq } { + }, #1 ) }
}

ExplSyntaxOff

begin{document}

newarray{xx}
readarray{xx}{1&2&3&4&5}

newarray{yy}
readarray{yy}{6&7&8&9&10}

begin{frame}
begin{table}
begin{tabular}{cccc}
No & xx & yy & zz \ hline
1 & xx{1} & yy{1} & fpeval{(xx{1}+yy{1})/2} \
2 & xx{2} & yy{2} & fpeval{(xx{2}+yy{2})/2} \
3 & xx{3} & yy{3} & \
4 & xx{4} & yy{4} & \
5 & xx{5} & yy{5} & \ hline
end{tabular}
end{table}
end{frame}

%newarray{zz}
%readarray{xx}{0&0&0&0&0}
newcountcounter
counter=5
loop
fpevalzz(counter){(xx(counter)+yy(counter))/2}
advance counter by -1
unlessifnum counter<1
repeat

end{document}









share|improve this question



























    1
















    How to store a calculated value in array?




    zz(1) = ( xx(1) + yy(1) )/2




    fpevalzz(counter){(xx(counter)+yy(counter))/2} NOT working




    documentclass{beamer}
    usepackage{siunitx,amsmath}
    usepackage{xparse,xfp}

    ExplSyntaxOn
    NewDocumentCommand{newarray}{m}
    {
    seq_new:c { l_hafid_array_#1_seq }
    cs_new:cpn { #1 } ##1
    {
    seq_item:cn { l_hafid_array_#1_seq } { ##1 }
    }
    }
    NewDocumentCommand{readarray}{mm}
    {
    seq_set_split:cnn { l_hafid_array_#1_seq } { & } { #2 }
    }
    cs_generate_variant:Nn seq_set_split:Nnn { c }

    NewExpandableDocumentCommand{sumarray}{O{15}m}
    {
    fp_eval:n { round( seq_use:cn { l_hafid_array_#2_seq } { + }, #1 ) }
    }

    ExplSyntaxOff

    begin{document}

    newarray{xx}
    readarray{xx}{1&2&3&4&5}

    newarray{yy}
    readarray{yy}{6&7&8&9&10}

    begin{frame}
    begin{table}
    begin{tabular}{cccc}
    No & xx & yy & zz \ hline
    1 & xx{1} & yy{1} & fpeval{(xx{1}+yy{1})/2} \
    2 & xx{2} & yy{2} & fpeval{(xx{2}+yy{2})/2} \
    3 & xx{3} & yy{3} & \
    4 & xx{4} & yy{4} & \
    5 & xx{5} & yy{5} & \ hline
    end{tabular}
    end{table}
    end{frame}

    %newarray{zz}
    %readarray{xx}{0&0&0&0&0}
    newcountcounter
    counter=5
    loop
    fpevalzz(counter){(xx(counter)+yy(counter))/2}
    advance counter by -1
    unlessifnum counter<1
    repeat

    end{document}









    share|improve this question

























      1












      1








      1









      How to store a calculated value in array?




      zz(1) = ( xx(1) + yy(1) )/2




      fpevalzz(counter){(xx(counter)+yy(counter))/2} NOT working




      documentclass{beamer}
      usepackage{siunitx,amsmath}
      usepackage{xparse,xfp}

      ExplSyntaxOn
      NewDocumentCommand{newarray}{m}
      {
      seq_new:c { l_hafid_array_#1_seq }
      cs_new:cpn { #1 } ##1
      {
      seq_item:cn { l_hafid_array_#1_seq } { ##1 }
      }
      }
      NewDocumentCommand{readarray}{mm}
      {
      seq_set_split:cnn { l_hafid_array_#1_seq } { & } { #2 }
      }
      cs_generate_variant:Nn seq_set_split:Nnn { c }

      NewExpandableDocumentCommand{sumarray}{O{15}m}
      {
      fp_eval:n { round( seq_use:cn { l_hafid_array_#2_seq } { + }, #1 ) }
      }

      ExplSyntaxOff

      begin{document}

      newarray{xx}
      readarray{xx}{1&2&3&4&5}

      newarray{yy}
      readarray{yy}{6&7&8&9&10}

      begin{frame}
      begin{table}
      begin{tabular}{cccc}
      No & xx & yy & zz \ hline
      1 & xx{1} & yy{1} & fpeval{(xx{1}+yy{1})/2} \
      2 & xx{2} & yy{2} & fpeval{(xx{2}+yy{2})/2} \
      3 & xx{3} & yy{3} & \
      4 & xx{4} & yy{4} & \
      5 & xx{5} & yy{5} & \ hline
      end{tabular}
      end{table}
      end{frame}

      %newarray{zz}
      %readarray{xx}{0&0&0&0&0}
      newcountcounter
      counter=5
      loop
      fpevalzz(counter){(xx(counter)+yy(counter))/2}
      advance counter by -1
      unlessifnum counter<1
      repeat

      end{document}









      share|improve this question















      How to store a calculated value in array?




      zz(1) = ( xx(1) + yy(1) )/2




      fpevalzz(counter){(xx(counter)+yy(counter))/2} NOT working




      documentclass{beamer}
      usepackage{siunitx,amsmath}
      usepackage{xparse,xfp}

      ExplSyntaxOn
      NewDocumentCommand{newarray}{m}
      {
      seq_new:c { l_hafid_array_#1_seq }
      cs_new:cpn { #1 } ##1
      {
      seq_item:cn { l_hafid_array_#1_seq } { ##1 }
      }
      }
      NewDocumentCommand{readarray}{mm}
      {
      seq_set_split:cnn { l_hafid_array_#1_seq } { & } { #2 }
      }
      cs_generate_variant:Nn seq_set_split:Nnn { c }

      NewExpandableDocumentCommand{sumarray}{O{15}m}
      {
      fp_eval:n { round( seq_use:cn { l_hafid_array_#2_seq } { + }, #1 ) }
      }

      ExplSyntaxOff

      begin{document}

      newarray{xx}
      readarray{xx}{1&2&3&4&5}

      newarray{yy}
      readarray{yy}{6&7&8&9&10}

      begin{frame}
      begin{table}
      begin{tabular}{cccc}
      No & xx & yy & zz \ hline
      1 & xx{1} & yy{1} & fpeval{(xx{1}+yy{1})/2} \
      2 & xx{2} & yy{2} & fpeval{(xx{2}+yy{2})/2} \
      3 & xx{3} & yy{3} & \
      4 & xx{4} & yy{4} & \
      5 & xx{5} & yy{5} & \ hline
      end{tabular}
      end{table}
      end{frame}

      %newarray{zz}
      %readarray{xx}{0&0&0&0&0}
      newcountcounter
      counter=5
      loop
      fpevalzz(counter){(xx(counter)+yy(counter))/2}
      advance counter by -1
      unlessifnum counter<1
      repeat

      end{document}






      fp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 20 mins ago









      sandusandu

      3,68442856




      3,68442856






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I did not really try to make your example work but would like to propose an alternative way of doing what I think you want to do.



          documentclass{beamer}
          usepackage{pgfmath}

          begin{document}

          defxx{{1,2,3,4,5}}
          defyy{{6,7,8,9,10}}

          newcommand{Parse}[1]{pgfmathparse{#1}pgfmathresult}

          begin{frame}
          begin{table}
          begin{tabular}{cccc}
          No & xx & yy & zz \ hline
          1 & Parse{xx[0]} & Parse{yy[0]} & Parse{xx[0]/2+yy[0]/2}\
          2 & Parse{xx[1]} & Parse{yy[1]} & Parse{xx[1]/2+yy[1]/2}\
          3 & Parse{xx[2]} & Parse{yy[2]} & Parse{xx[2]/2+yy[2]/2}\
          4 & Parse{xx[3]} & Parse{yy[3]} & Parse{xx[3]/2+yy[3]/2}\
          5 & Parse{xx[4]} & Parse{yy[4]} & Parse{xx[4]/2+yy[4]/2}\
          hline
          end{tabular}
          end{table}

          newcounter{counter}
          setcounter{counter}{4}
          loop
          Parse{xx[numbervalue{counter}]/2+yy[numbervalue{counter}]/2}
          addtocounter{counter}{-1}
          unlessifnumnumbervalue{counter}=-1
          repeat
          end{frame}
          end{document}


          enter image description here





          share























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            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/3.0/"u003ecc by-sa 3.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%2ftex.stackexchange.com%2fquestions%2f480828%2fhow-to-store-values-in-an-array%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









            0














            I did not really try to make your example work but would like to propose an alternative way of doing what I think you want to do.



            documentclass{beamer}
            usepackage{pgfmath}

            begin{document}

            defxx{{1,2,3,4,5}}
            defyy{{6,7,8,9,10}}

            newcommand{Parse}[1]{pgfmathparse{#1}pgfmathresult}

            begin{frame}
            begin{table}
            begin{tabular}{cccc}
            No & xx & yy & zz \ hline
            1 & Parse{xx[0]} & Parse{yy[0]} & Parse{xx[0]/2+yy[0]/2}\
            2 & Parse{xx[1]} & Parse{yy[1]} & Parse{xx[1]/2+yy[1]/2}\
            3 & Parse{xx[2]} & Parse{yy[2]} & Parse{xx[2]/2+yy[2]/2}\
            4 & Parse{xx[3]} & Parse{yy[3]} & Parse{xx[3]/2+yy[3]/2}\
            5 & Parse{xx[4]} & Parse{yy[4]} & Parse{xx[4]/2+yy[4]/2}\
            hline
            end{tabular}
            end{table}

            newcounter{counter}
            setcounter{counter}{4}
            loop
            Parse{xx[numbervalue{counter}]/2+yy[numbervalue{counter}]/2}
            addtocounter{counter}{-1}
            unlessifnumnumbervalue{counter}=-1
            repeat
            end{frame}
            end{document}


            enter image description here





            share




























              0














              I did not really try to make your example work but would like to propose an alternative way of doing what I think you want to do.



              documentclass{beamer}
              usepackage{pgfmath}

              begin{document}

              defxx{{1,2,3,4,5}}
              defyy{{6,7,8,9,10}}

              newcommand{Parse}[1]{pgfmathparse{#1}pgfmathresult}

              begin{frame}
              begin{table}
              begin{tabular}{cccc}
              No & xx & yy & zz \ hline
              1 & Parse{xx[0]} & Parse{yy[0]} & Parse{xx[0]/2+yy[0]/2}\
              2 & Parse{xx[1]} & Parse{yy[1]} & Parse{xx[1]/2+yy[1]/2}\
              3 & Parse{xx[2]} & Parse{yy[2]} & Parse{xx[2]/2+yy[2]/2}\
              4 & Parse{xx[3]} & Parse{yy[3]} & Parse{xx[3]/2+yy[3]/2}\
              5 & Parse{xx[4]} & Parse{yy[4]} & Parse{xx[4]/2+yy[4]/2}\
              hline
              end{tabular}
              end{table}

              newcounter{counter}
              setcounter{counter}{4}
              loop
              Parse{xx[numbervalue{counter}]/2+yy[numbervalue{counter}]/2}
              addtocounter{counter}{-1}
              unlessifnumnumbervalue{counter}=-1
              repeat
              end{frame}
              end{document}


              enter image description here





              share


























                0












                0








                0







                I did not really try to make your example work but would like to propose an alternative way of doing what I think you want to do.



                documentclass{beamer}
                usepackage{pgfmath}

                begin{document}

                defxx{{1,2,3,4,5}}
                defyy{{6,7,8,9,10}}

                newcommand{Parse}[1]{pgfmathparse{#1}pgfmathresult}

                begin{frame}
                begin{table}
                begin{tabular}{cccc}
                No & xx & yy & zz \ hline
                1 & Parse{xx[0]} & Parse{yy[0]} & Parse{xx[0]/2+yy[0]/2}\
                2 & Parse{xx[1]} & Parse{yy[1]} & Parse{xx[1]/2+yy[1]/2}\
                3 & Parse{xx[2]} & Parse{yy[2]} & Parse{xx[2]/2+yy[2]/2}\
                4 & Parse{xx[3]} & Parse{yy[3]} & Parse{xx[3]/2+yy[3]/2}\
                5 & Parse{xx[4]} & Parse{yy[4]} & Parse{xx[4]/2+yy[4]/2}\
                hline
                end{tabular}
                end{table}

                newcounter{counter}
                setcounter{counter}{4}
                loop
                Parse{xx[numbervalue{counter}]/2+yy[numbervalue{counter}]/2}
                addtocounter{counter}{-1}
                unlessifnumnumbervalue{counter}=-1
                repeat
                end{frame}
                end{document}


                enter image description here





                share













                I did not really try to make your example work but would like to propose an alternative way of doing what I think you want to do.



                documentclass{beamer}
                usepackage{pgfmath}

                begin{document}

                defxx{{1,2,3,4,5}}
                defyy{{6,7,8,9,10}}

                newcommand{Parse}[1]{pgfmathparse{#1}pgfmathresult}

                begin{frame}
                begin{table}
                begin{tabular}{cccc}
                No & xx & yy & zz \ hline
                1 & Parse{xx[0]} & Parse{yy[0]} & Parse{xx[0]/2+yy[0]/2}\
                2 & Parse{xx[1]} & Parse{yy[1]} & Parse{xx[1]/2+yy[1]/2}\
                3 & Parse{xx[2]} & Parse{yy[2]} & Parse{xx[2]/2+yy[2]/2}\
                4 & Parse{xx[3]} & Parse{yy[3]} & Parse{xx[3]/2+yy[3]/2}\
                5 & Parse{xx[4]} & Parse{yy[4]} & Parse{xx[4]/2+yy[4]/2}\
                hline
                end{tabular}
                end{table}

                newcounter{counter}
                setcounter{counter}{4}
                loop
                Parse{xx[numbervalue{counter}]/2+yy[numbervalue{counter}]/2}
                addtocounter{counter}{-1}
                unlessifnumnumbervalue{counter}=-1
                repeat
                end{frame}
                end{document}


                enter image description here






                share











                share


                share










                answered 2 mins ago









                marmotmarmot

                110k5137256




                110k5137256






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX 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.


                    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%2ftex.stackexchange.com%2fquestions%2f480828%2fhow-to-store-values-in-an-array%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

                    サソリ

                    広島県道265号伴広島線

                    Setup Asymptote in Texstudio