How to export a symbolic matrix to excel ?












1















I want to calculate a matrix with symbolic entries and export the matrix to an excel file.



Approach:



syms x_1 y_1
A_sym = sym(zeros(2,2));
A_sym(1,1) = x_1;
A_sym(2,1) = x_1 * y_1
A_sym(2,2) = y_1;


I tried to use the xlswrite('test.xls',A_sym,'A1:C5') function but it is somehow not designed for symbolic expressions and I get the following error:





Input data must be a numeric, cell, or logical array.





Afterwards I tried to typecast the content of my matrix to char and export it again:



 B = char(A); 
xlswrite('test.xls',B,'A1:C5');


The result was that the function exported each character into a single excel cell which leads to the problem that the symbolic variables containing more than one char are not in one single excel cell but are divided into many cells which is useless for my purposes.



I guess there must be a better solution to export the variables into a single cell.



Does someone has a good solution ?










share|improve this question



























    1















    I want to calculate a matrix with symbolic entries and export the matrix to an excel file.



    Approach:



    syms x_1 y_1
    A_sym = sym(zeros(2,2));
    A_sym(1,1) = x_1;
    A_sym(2,1) = x_1 * y_1
    A_sym(2,2) = y_1;


    I tried to use the xlswrite('test.xls',A_sym,'A1:C5') function but it is somehow not designed for symbolic expressions and I get the following error:





    Input data must be a numeric, cell, or logical array.





    Afterwards I tried to typecast the content of my matrix to char and export it again:



     B = char(A); 
    xlswrite('test.xls',B,'A1:C5');


    The result was that the function exported each character into a single excel cell which leads to the problem that the symbolic variables containing more than one char are not in one single excel cell but are divided into many cells which is useless for my purposes.



    I guess there must be a better solution to export the variables into a single cell.



    Does someone has a good solution ?










    share|improve this question

























      1












      1








      1








      I want to calculate a matrix with symbolic entries and export the matrix to an excel file.



      Approach:



      syms x_1 y_1
      A_sym = sym(zeros(2,2));
      A_sym(1,1) = x_1;
      A_sym(2,1) = x_1 * y_1
      A_sym(2,2) = y_1;


      I tried to use the xlswrite('test.xls',A_sym,'A1:C5') function but it is somehow not designed for symbolic expressions and I get the following error:





      Input data must be a numeric, cell, or logical array.





      Afterwards I tried to typecast the content of my matrix to char and export it again:



       B = char(A); 
      xlswrite('test.xls',B,'A1:C5');


      The result was that the function exported each character into a single excel cell which leads to the problem that the symbolic variables containing more than one char are not in one single excel cell but are divided into many cells which is useless for my purposes.



      I guess there must be a better solution to export the variables into a single cell.



      Does someone has a good solution ?










      share|improve this question














      I want to calculate a matrix with symbolic entries and export the matrix to an excel file.



      Approach:



      syms x_1 y_1
      A_sym = sym(zeros(2,2));
      A_sym(1,1) = x_1;
      A_sym(2,1) = x_1 * y_1
      A_sym(2,2) = y_1;


      I tried to use the xlswrite('test.xls',A_sym,'A1:C5') function but it is somehow not designed for symbolic expressions and I get the following error:





      Input data must be a numeric, cell, or logical array.





      Afterwards I tried to typecast the content of my matrix to char and export it again:



       B = char(A); 
      xlswrite('test.xls',B,'A1:C5');


      The result was that the function exported each character into a single excel cell which leads to the problem that the symbolic variables containing more than one char are not in one single excel cell but are divided into many cells which is useless for my purposes.



      I guess there must be a better solution to export the variables into a single cell.



      Does someone has a good solution ?







      excel matlab






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 10:22









      Nils Nils

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          1














          If what you want is an output based on text, then you are on the right trach, but you need to do what you are doing per matrix element.



          for ii=1:size(A_sym,1)
          for jj=1:size(A_sym,2)
          B{ii,jj}=char(A_sym(ii,jj));
          end
          end

          xlswrite('test.xls',B);


          This will put a char version of the symbolic matrix with the same size in excel (in this case 2x2)






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53335832%2fhow-to-export-a-symbolic-matrix-to-excel%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









            1














            If what you want is an output based on text, then you are on the right trach, but you need to do what you are doing per matrix element.



            for ii=1:size(A_sym,1)
            for jj=1:size(A_sym,2)
            B{ii,jj}=char(A_sym(ii,jj));
            end
            end

            xlswrite('test.xls',B);


            This will put a char version of the symbolic matrix with the same size in excel (in this case 2x2)






            share|improve this answer




























              1














              If what you want is an output based on text, then you are on the right trach, but you need to do what you are doing per matrix element.



              for ii=1:size(A_sym,1)
              for jj=1:size(A_sym,2)
              B{ii,jj}=char(A_sym(ii,jj));
              end
              end

              xlswrite('test.xls',B);


              This will put a char version of the symbolic matrix with the same size in excel (in this case 2x2)






              share|improve this answer


























                1












                1








                1







                If what you want is an output based on text, then you are on the right trach, but you need to do what you are doing per matrix element.



                for ii=1:size(A_sym,1)
                for jj=1:size(A_sym,2)
                B{ii,jj}=char(A_sym(ii,jj));
                end
                end

                xlswrite('test.xls',B);


                This will put a char version of the symbolic matrix with the same size in excel (in this case 2x2)






                share|improve this answer













                If what you want is an output based on text, then you are on the right trach, but you need to do what you are doing per matrix element.



                for ii=1:size(A_sym,1)
                for jj=1:size(A_sym,2)
                B{ii,jj}=char(A_sym(ii,jj));
                end
                end

                xlswrite('test.xls',B);


                This will put a char version of the symbolic matrix with the same size in excel (in this case 2x2)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 10:32









                Ander BiguriAnder Biguri

                26.7k105693




                26.7k105693
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f53335832%2fhow-to-export-a-symbolic-matrix-to-excel%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

                    Bressuire

                    Vorschmack

                    Quarantine