MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

Exchange Data Between MATLAB and Excel

Alex Roumi, MathWorks

Exchange data between MATLAB® and Microsoft® Excel® and display the results back into Excel. We create a diagonal matrix using the the Spreadsheet Link add-in or using a VBA code and, finally, using MATLAB function wizard, which helps you learn how to use the MATLAB sub function.

In this video I am going to show you how to exchange data between MATLAB and MS Excel in three different ways through an example.

  1. Excel Ribbon
  2. In a worksheet, enter the numbers 1 through 5 into the range of cells from A1 through E1.

    Define the name testData for this range of cells.

    On the Home tab, click the MATLAB group then select Send named ranges to MATLAB.

    Select Run MATLAB Command.

    Use the diag function to specify testData as the input argument. d = diag(testData)

    Select Get data from MATLAB.

    Enter d in the dialog box to get the diagonal matrix.

     

  3. VBA macro
  4. Spreadsheet Link allows you to execute MATLAB functions in VBA if you use macros to automate your data-processing calculation.

    In the Code section, enter this VBA code that contains a macro named Diagonal.

    Sub Diagonal()
    MLPutRanges
    MLEvalString "b = diag(testData);"
    MLGetMatrix "b", "A3"
    MatlabRequest
    End Sub

    This code sends the named ranges to MATLAB, creates the diagonal matrix, and places it at cell A3.

    Run the macro by clicking Run, Run Sub/UserForm.

  5. MATLAB Function Wizard
  6. You can select MATLAB function wizard from the MATLAB group.

    In the MATLAB command window, locate the diag function by entering which diag. Choose the category matlab\elmat and function diag.

    Specify testData as the input argument of V and the output cell A3. The diagonal matrix is placed at cell A3.

    By double-clicking on the cell where it shows zero, you can learn the syntax of matlabsub function.

To recap, we have seen in this video how exchange and manipulate data in MATLAB from Excel in three different ways. To find out more about the capabilities of Spreadsheet Link, please visit the Spreadsheet Link product page, where you can read the documentations, watch additional videos, and find examples. Thank you for watching.

Related Products

  • Spreadsheet Link
  • MATLAB

Learn More

Download code

Feedback

Featured Product

Spreadsheet Link

  • Request Trial
  • Get Pricing

Up Next:

10:38
Passing Data Between GUIDE Callbacks Without Globals in...

Related Videos:

5:10
Reading Excel Data into MATLAB with a GUI, Part 4
13:48
Reading Excel Data into MATLAB with a GUI, Part 3
6:52
Saving Data from MATLAB to Excel Using a Template
5:05
Reading Excel Data into MATLAB with a GUI, Part 2

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Contact Sales
  • About MathWorks

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

  • Select a Web Site United States
  • Patents
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2021 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation