How can i create a variable with a xlsx file so it can be read in a lookup table block?

Tomás Glória
Tomás Glória New Altair Community Member
edited February 2022 in Community Q&A

Hi, 

I am trying to convert a matlab-simulink projeto to activate but i dont know how i can create a variable with a xlsx file so it can be easly edited and read in a lookup table block. In matlab there´s the function xlsread() witch does that, bue i dont know how can i do it in activate. Can you help me?

 

Thank you, 

Tomás Glória.

Answers

  • RoKet
    RoKet
    Altair Employee
    edited February 2022

    Hi Tomás,

    In Activate you also can use xlsread in Model or Diagram context, e. g.

    [mat, txt, raw] = xlsread([filepath filename], 1, 'A1:I60');

    Now you can access single cells

    mat(2, 5);

    or even rows and lines. The rows or lines can be used for input of lookup table data.

    For additional info please have a look at the help: xlsread.

    RoKet

  • Tomás Glória
    Tomás Glória New Altair Community Member
    edited February 2022

    Hi Tomás,

    In Activate you also can use xlsread in Model or Diagram context, e. g.

    [mat, txt, raw] = xlsread([filepath filename], 1, 'A1:I60');

    Now you can access single cells

    mat(2, 5);

    or even rows and lines. The rows or lines can be used for input of lookup table data.

    For additional info please have a look at the help: xlsread.

    RoKet

    thank your for answer the question.

    I tried to make a super simples model and use xlsread in Model initialization but it doesnt recogniz it.

    image

    Do you have any idea why?

  • RoKet
    RoKet
    Altair Employee
    edited February 2022

    Not really.

    xlsread is available both in Personal and Business Edition, I use 2021.2, but it has been supported for a long time.

    One limitation (according to help): xlsread is available only on Windows systems where Microsoft Excel is installed.

    Another quick check: if you also have Compose installed, you can try xlsread there. Both Activate and Compose use the same implementation of oml.

  • Tomás Glória
    Tomás Glória New Altair Community Member
    edited February 2022

    Not really.

    xlsread is available both in Personal and Business Edition, I use 2021.2, but it has been supported for a long time.

    One limitation (according to help): xlsread is available only on Windows systems where Microsoft Excel is installed.

    Another quick check: if you also have Compose installed, you can try xlsread there. Both Activate and Compose use the same implementation of oml.

    Yes, i have Microsoft Excel installed and on compose it works, i just dont get it why it doesn´t in activate.

    Thank you for answering any way!

  • RoKet
    RoKet
    Altair Employee
    edited February 2022

    Next try.

    1. I've created a very simple model with lookup table and xlsread in initialization as well as an Excel file. Please give it a try.

    2. If it fails, just call xlsread('pathandexcelfile') in OML Command Window.

  • Tomás Glória
    Tomás Glória New Altair Community Member
    edited February 2022

    Next try.

    1. I've created a very simple model with lookup table and xlsread in initialization as well as an Excel file. Please give it a try.

    2. If it fails, just call xlsread('pathandexcelfile') in OML Command Window.

    I keeps sending the same error: image

    Although i noitice now when i open the Activate it sends an error immediately do you know what can it be?

     

  • RoKet
    RoKet
    Altair Employee
    edited February 2022

    That was a good hint! Unfortunately, Activate can't handle special characters in the user path (and I assume not in other paths either).

    Can you change the user name (with impact on c:\users\username) or create another user to check it?

  • Tomás Glória
    Tomás Glória New Altair Community Member
    edited February 2022

    That was a good hint! Unfortunately, Activate can't handle special characters in the user path (and I assume not in other paths either).

    Can you change the user name (with impact on c:\users\username) or create another user to check it?

    I tried to change the user folder name but i wasnt successful. However a friend of mine dont have any special character in  the user path and still have that some error ("xlsread is not defined").

    Sorry for taking so long to respond, had some really busy days.

  • RoKet
    RoKet
    Altair Employee
    edited February 2022

    The main issue is a special character in user path resp. Activate's inability to process utf8. As a result, neither Activate_startup.oml nor some toolboxes (like xls-toolbox) can be loaded automatically. This will be fixed in the next release.

    An intermediate solution is to manually load the xls-toolbox (addtoolbox(‘omlxlstoolbox’)) in oml command window or model context.