Matlab with Word, Excel, PowerPoint

xiaoxiao2021-03-06  115

Responding to the call of the version of LiGuowen, in order to obtain a May 1st labor certificate, I will not have a holiday, I hope to get this award in the coming year. In this May 1st, I wrote the summary of my previous studies to everyone, and I hope everyone will come to this award.

MATLAB connection to Microsoft Excel

This chapter requires readers to have a certain experience of using Matlab and Microsoft Excel. This section describes how to use Matlab Excel Builder to implement Matlab and Microsoft Excel connectivity, thereby implementing a seamless interface of both. I hope that through this chapter, it is possible to let the readers have a more in-depth understanding of the ideas and practical applications of Excel connection. Through both connections, readers can make readers more easily intuitive processing data. In MATLAB6.5, the connection is implemented by Excel Link, which is not involved in this chapter.

1. Reader preparation knowledge

Read this chapter content, readers need to be familiar with the following:

(1) Familiar with Matlab and Matlab compilers;

(2) Microsoft Excel;

(3) Visual Basic for Applications (VBA).

2. Compiler

Not all compilers support COM components, Excel Builder can use the following compiler:

(1) Borland C Builder 4;

(2) Borland C Builder 5;

(3) BORLAND C Builder 6;

(4) Microsoft Visual Studio 5.0;

(5) Microsoft Visual Studio 6.0; (6) Microsoft Visual Studio .NET.

---------------------------------------------- 公,, honesty, Yong, Yi Xuexuan, Arctic brilliant; Ze was sent by Wanfang, Xiao Xiangxiang; 哉 府 府Director of the work;

10.1 Implementation matrix output in Excel

MATLAB EXCEL Builder's constraints and restrictions are the same as the MATLAB compiler, but there must be a little attention to the EXCEL ADD-IN file encoded under a version, can only perform tasks under the same versions, for example, encoded in Excel 97 Files cannot work in Excel 2000.

Establishing a call with Matlab Excel Builder mainly follows:

(1) Create a new project;

(2) Add M file or MEX file;

(3) Code the project;

(4) Test the model;

(5) Call;

(6) Package the program.

In this case, the above process is used to explain the above process.

[Example 10-1] How to see how to input the Rubik matrix in matlab into the Excel and display it. 1. Open Excel Builder

Type MXLTOOL in the MATLAB command window, or select [Start | Matlab | Matlab Excel Builder | MATLAB EXCEL Builder] to activate the Excel Builder window, Figure 10-1 is Excel Builder.

2. Establish a project

Select the [File | New Project] menu in Excel Builder, as shown in Figure 10-2, and make the following settings in the New Project Settings dialog:

(1) Enter xlmagic in the Component Name text box;

(2) Press the Tab key or click on another text box with the mouse to make the default settings. Keep the XLmagic in the Class Name text box;

(3) The default 1.0 is unchanged in the Project Version text box;

(4) In the Project Directory text box, the default work directory is MATLAB's working directory, remains unchanged, if this directory does not exist, OK, the system prompts to create new, select Yes;

(5) Select C in the Compile Code in single selection column;

(6) All vacancy in the Compile Options multi-selection column is not selected.

3. Write M files

In fact, mymagic.m file is very simple, its contents are as follows:

Function y = mymagic (x)

Y = MAGIC (X)

Save the file to the / WORK / XLMAGIC folder.

This topic related pictures are as follows: Figure 10-1Matlab Excel Builder Graphics Interactive Window This topic Related Images: Figure 10-2 Settings Dialog ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------- Public, sincerity, Yong, Yi Xunxuan, the North Pole is brilliant; Ze is won by Wanfang, Qing Xiangxiang; 巍哉Search, refreshing the article; the national education, the national is Shengqiang; the wall of the thousand, the steel; the martial arts, for the workshops; the public and brave, Yongya is forgotten; Guanghua is brilliant, west, west!

3. Construction project:

(1) Click the [Add File] button in the MATLAB Excel Builder Graphic Interactive window;

(2) Select mymagic.m file from the / WORK / XLmagic folder.

(3) Click the [Build] button or select the [Excel | COM Files] menu from the build menu to encode the file.

4. Add the Excel Builder COM function to Excel

(1) Open Excel software;

(2) Open file /work/xlmagic/mymagic.xls. Note: Excel will prompt the file containing macro information, select Enable Macro to run this example;

(3) Excel main window (not the Visual Basic Edit window) Press Alt F8, or select [Tools | Macro | Macro] menu. From the dialog box, select MyMagic operation, as shown in Figure 10-3: (4) Re-opening the macro dialog, select MyMagic_Transpose, then run the Rubik matrix of the transpose, as shown in Figure 10-4: (5) Open again Macro dialog, select MyMagic_resize, then run, but returned is still a fourth-order Rubic Cube Matrix. Change the numbers in the A32 unit to 6, you can get the results as shown in Figure 10-5: This topic related pictures are as follows: Figure 10-3 Returns the EXCEL form

The related pictures of this topic are as follows: Figure 10-4 After the transposition, the Mo's Cube Matrix

The related pictures of this topic are as follows: Figure 10-5 After the expansion of the Rubika matrix

Note: If you want to change the size of the Mo's matrix again, you can only increase the order of matrix. If it is already 6th, you can only change it to 6th order, otherwise the result is not allowed.

Recommendation: You can first remove all the values ​​of the Rubik matrix, then change 6 in the A32 unit to 4 to see the result.

---------------------------------------------- 公,, honesty, Yong, Yi Xuexuan, Arctic brilliant; Ze was sent by Wanfang, Xiao Xiangxiang; 哉 府 府Director of the work;

Matlab connection to Microsoft Word

It is very stronger to mention Mathcad text processing, then how will Matlab's text processing? MathWorks developed MATLAB Notebook successfully combined Microsoft Word and Matlab to create a perfect working environment for text processing, scientific computing and engineering design. This MATLAB not only has the original computing power, but also adds the editing ability of the Word software, but also throws Mathcad behind. MATLAB Notebook can always modify the calculation command at any time in Word, calculate and generate images returned, enable users to "enjoy" Matlab's vast science and technology resources in the Word environment. Matlab Notebook works: Users create commands in the Word document, and then delivered to the background of MATLAB, and finally returns the result to Word.

It is recommended to write scientific and technological reports, papers, and monographs using Matlab Notebook, suggest teaching, teachers who write nature of artics use MATLAB Notebook, which recommends using MATLAB Notebook for the study of artistic subject exercises. The powerful feature of Matlab Notebook will make you more than half.

1 Install Matlab Notebook

As you can see from the above introduction, you must have Word and Matlab in your computer when using Matlab Notebook. This book is taken by Matlab6.5 and Word2000. The MATLAB Notebook file is also known as the m-book file. The Notebook of Matlab6.5 is installed in a MATLAB environment. Specific steps are as follows:

(1) Install Matlab6.5 and Word2000 separately in the system, and launch the MATLAB6.5 command window;

(2) Enter: >> Notebook -Setup in the command window: >> Notebook -setup

Will get the following tips:

Welcome to the utility for setting up the matlab notebook

For Interfacing Matlab To Microsoft Word

Choose Your Version of Microsoft Word:

[1] Microsoft Word 97

[2] Microsoft Word 2000

[3] Microsoft Word 2002 (XP)

[4] EXIT, MAKING No Changes

(3) Select the corresponding code according to the version of the installed Word, this article is as follows:

Microsoft Word Version: 2

Notebook setup is completion.

This way you can use Matlab Notebook. There are two ways to open a M-book file.

(1) Type the command directly to create or open a m-book file directly at the Matlab Command Window:

>> Notebook% New M-Book (Not recommended, often errors in my computer)

>> Notebook C: /Documents/mymbook.doc% Opens a M-Book already existing

(2) Open Word2000 first, then open the file (f) / new (do not click the New Buttons directly), pop up the Figure 11-1 dialog box. Select the M-Book template. There will be a menu bar in the black circle in Figure 11-2 in the new Word document.

This topic related pictures are as follows: Figure 11-1 Creating a M-Book File dialog

The related pictures of this topic are as follows: Figure 11-2 Notebook menu bar

2 use Matlab Notebook

Notebook is interacting with MATLAB through dynamic links. The basic unit of Notebook and MATLAB interaction is cell. Notebook needs to enter a command in MATLAB to form a cell, then transferred to MATLAB, running the result of the output, and then returns Notebook in the cell.

1. The basic process of executing commands in Word

Notebook uses input cells to define the MATLAB input command. Proceed as follows:

(1) Enter the command in the text format, do not press Enter and Spacebar at the end of the command;

(2) Select the "Define Input Cell" option from the Notebook menu to define input cells;

(3) Select the "Evaluate Cell" option or Ctrl ENTER from the Notebook menu.

Where input cells are displayed as a green character included in black, and the output cells are blue characters included in black brackets. If the wrong black brackets include red characters, other texts are default to black characters. As follows: (Author Note: No specially labeled behavior blue)

M = Eye (3) (Author Note: This behavior is green)

m =

1 0 0

0 1 0

0 0 1

M / 0 (Author Note: This behavior is green)

Warning: Divide by Zero.

(Type "Warning Off Matlab: DivideByzero" To Suppress this Warning.)

ANS =

Inf nan nan

Nan Inf Nannan Nan Inf

M = Eye (3) n = EYE (4) (Author Note: This behavior is green)

??? format compact; m = Eye (3) n = EEE (4)

(Author Note: This line and two lines are red)

Error: Missing Operator, Comma, or Semicolon. Green)

2. Example explanation

[Example 11-1] Execute code in a piece of text

In matlab, the input cells can be operated in the middle of the text without affecting other texts. Proceed as follows:

(1) The input sample is as follows, and M = EEE (3) is placed in the middle of the text.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Have you been "Dynamics and Control Technology" Forum? M = Eye (3) There are many good things there.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(2) Select the command as follows:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Have you been "Dynamics and Control Technology" Forum? M = Eye (3) There are many good things there.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(3) Select the "Evaluate Cell" option or Ctrl ENTER from the Notebook menu. A similar result will occur in the above example.

(4) If you want to convert the output cell into normal text, select the cells to be converted, then select the "undefine cells" option or Alt U from the Notebook menu. Executive results are shown in Figure 12-3.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Have you been "Dynamics and Control Technology" Forum? M = Eye (3) There are many good things there. %%%%%%%%%%%%%%%%%%%%%%%%%%%%

m =

1 0 0

0 1 0

0 0 1

[Example 11-2] Draw a picture

Multi-graphical instructions that generate full graphics must be defined in the same cell population

T = 0: 0.1: 20; Y = 1-COS (T). * Exp (-T / 5);

Time = [0, 20, 20, 0];

Amplitude = [0.95, 0.95, 1.05, 1.05];

Fill (Time, Amplitude, 'G'), AXIS ([0, 20, 0, 2]);

Xlabel ('Time'), YLabel ('amplitude');

Hold On

Plot (T, Y, 'R', 'LineWidth', 2)

Hold Off

YMAX = min (Y)

Write the above program to Word, then all select, then select [Notebook | Define Input Cell], and finally select the [Evaluate Cell] option from the Notebook menu, or Ctrl Enter. Get the following results

T = 0: 0.1: 20; Y = 1-COS (T). * Exp (-T / 5);

Time = [0, 20, 20, 0];

Amplitude = [0.95, 0.95, 1.05, 1.05];

Fill (Time, Amplitude, 'G'), AXIS ([0, 20, 0, 2]), XLabel ('Time'), YLabel ('Amplitude');

Hold On

Plot (T, Y, 'R', 'Linewidth', 2) Hold Off

YMAX = min (Y)

YMAX =

0

Matlab connection to Microsoft PowerPoint

Matlab and Microsoft PowerPoint connections are still Matlab Notebook. This section is simple to talk about how to make our speeches more interactive, allowing our speeches to perform complicated scientific calculations or changing parameters and perform real-time calculations, and give value and graphics results. With this speech, I believe it is more attractive, closer to the distance between the listener.

Below we have introduced what we can do through three instances.

1. Realize the speech of calculation and visualization in M-Book

This example is made as shown in Figure 12-3 PowerPoint.

The slide is played in order, but the overline with underlined slides is set to have a super connection. After clicking on the hyperlink, you will go to the corresponding Word file.

Let's take a brief introduction to the production step of the PowerPoint document, saved as Dytrol.ppt:

(1) Start PowerPoint, select a blank document in the dialog box, click the [OK] button;

(2) Option there in the automatic template of the new slide, this example is the first one;

(3) In the newly built template, according to Figure 12-3.

(4) Select the "MATLAB Extension Programming" text, select the main menu [Insert | Hyper Link], select the M-Book file ready in advance in the Link File box. This enters the Notebook environment. Once entered this environment, most of MATLAB can be realized.

Note: The M-Book file pointed to by the hyperlink must be ready in advance. See the next section of the M-Book production.

The related pictures of this topic are as follows: Figure 11-3 PowerPoint Run interface

转载请注明原文地址:https://www.9cbs.com/read-125669.html

New Post(0)