Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Report production when Using a GUI

Subject: Report production when Using a GUI

From: Jeff

Date: 1 Nov, 2010 17:37:04

Message: 1 of 13

I typically use GUI's for many of my projects - up until now they have been MS Excel, but am trying to convert to MatLab. One of my issues at the moment is producing quality reports after the user has entered the necessary data. My question is is it typical to have a separate .m file to produce the report that is run in the background from the primary GUI?

Also, on a side note, does anyone know if MathWorks will ever institue a real multitab interface?

Thanks,
Jeff

Subject: Report production when Using a GUI

From: Eric

Date: 1 Nov, 2010 19:02:08

Message: 2 of 13

Regarding the quality reports: You might be better off creating reports as Word documents from Matlab via the COM interface. It seems you're experienced with VBA for Excel at least, so I don't think you'll find this very difficult. I've done things like the following:

1. Load a customized template
2. Insert text as paragraphs
3. Insert data as a table
4. Insert figures (with captions)
5. Embed documents used in the analysis

You can end up with reports that look very professional.

Regarding the lack of a multitab control: My guess is this will eventually make it into GUIDE. But GUIDE seems to evolve slowly. It's not as satisfying a solution, but you can look at the file exchange as well. For instance

http://www.mathworks.com/matlabcentral/fileexchange/6996-tabpanel-constructor-v2-8-2010

Good luck,
Eric

Subject: Report production when Using a GUI

From: Jeff

Date: 1 Nov, 2010 19:17:05

Message: 3 of 13

Thanks, Eric. I'm not familiar with the COM interface to MS Word. Would you say it is better than the Report Generator?

Subject: Report production when Using a GUI

From: Eric

Date: 1 Nov, 2010 19:59:04

Message: 4 of 13

It's definitely better than the report generator.

Here's some sample code to get you started and show how things are done. I can't post code I write at work, unfortunately.

%% Start Microsoft Word
Word_COM = actxserver('Word.Application');
set(Word_COM,'Visible',1);%Make Word visible

%% Create a document
File_COM = Word_COM.Documents.Add;%Creates a new document

%% Go to the end of the file
wdStory = 6;
Word_COM.Selection.EndKey(wdStory);

%% Add some text
Word_COM.Selection.TypeText('Hello World!');
Word_COM.Selection.TypeParagraph;


To add a figure, use Matlab's print() function to print to a PNG file. Then use something like:

Word_COM.Selection.InlineShapes.AddPicture(PNG_path_and_filename);
Word_COM.Selection.MoveRight(1);
Word_COM.Selection.TypeParagraph;

The key for me (since I know Matlab well but not always VBA) is to use the Word macro editor to figure out how to do stuff in VBA, then do the same thing in Matlab using the Word_COM and File_COM objects. Of course I can't remember if Word 2010 still has the macro recorder or not, so that may no longer be an option.

-Eric

Subject: Report production when Using a GUI

From: Jeff

Date: 1 Nov, 2010 20:46:05

Message: 5 of 13

Interesting. Playing around with Word and COM. Is there a reference manual somewhere out there in MatLab world that describes the COm language and syntax?

Subject: Report production when Using a GUI

From: Eric

Date: 1 Nov, 2010 22:02:03

Message: 6 of 13

There are two good places to start:

1. http://www.mathworks.com/help/techdoc/matlab_external/bqdwu3j.html
This is the Matlab documentation on how to interact with COM objects. You can use Matlab's get() and set() functions, but you can also use syntax like Word_COM.Visible = 1 (more VBA-like syntax). The only time I've run into problems is sometimes Office objects let you do things like object.Items("Name") to get the particular name of an object from a collection. I've never found an analog in Matlab and always just end up looping through all items and finding a match.

2. Documentation in the Word Developer Reference
All of the objects, methods, and parameters you use are defined by Word. That's why the macro-editor is so handy. If you need to do something from Matlab, just record a macro and then perform what is usually a trivial translation to Matlab. Often no translation is needed at all. You also need this reference to explain enumerations that the macro editor will use.

You might also looks at the methodsview() function in Matlab. This is useful at times. If you call methodsview(Word_COM) you'll see all the methods defined for that object. In the Arguments list, the first argument is always "handle". That's the object itself and does not need to be repeated explicitly in the argument list. You can use get(Word_COM) to look at all of the parameters defined for the object as well.

-Eric

Subject: Report production when Using a GUI

From: Jeff

Date: 2 Nov, 2010 00:20:07

Message: 7 of 13

Eric,

Thanks so much for your help. Typically I like to present data in tables. Initially, I was thinking Word, but them relaized I should stick with Excell. I am very familiar with Excel VBA, but not Word. I started to look at Word VBA today, but did not like the format. So I'll probably go back to Excel as the depository for current data and report printing. Kinda of weird though using Excel just for printing. Guess that allows me to simply insert data into a certain cell easily unlike what I imagine it would take to do the same think in Word.

Is it just me or does it seem like MatLab just doesn't provide enough documentation on the various options and functionality of its publishing routines?

Thanks again Eric for your help.

Jeff

Subject: Report production when Using a GUI

From: ImageAnalyst

Date: 2 Nov, 2010 02:49:14

Message: 8 of 13

Jeff:
Here's some Microsoft sites that may help you. The code in Visual
Basic is very similar to the code you'd use from MATLAB with minor
differences (like double quotes get replaced by single quotes).
http://support.microsoft.com/kb/247412/EN-US/
http://msdn.microsoft.com/en-us/office/default.aspx

Excel 2007 Developer Reference
http://msdn.microsoft.com/en-us/library/bb242656%28office.12%29.aspx

Subject: Report production when Using a GUI

From: Yair Altman

Date: 2 Nov, 2010 05:54:04

Message: 9 of 13

"Jeff " <jagymg@yahoo.com> wrote in message <iamts0$5ht$1@fred.mathworks.com>...
> I typically use GUI's for many of my projects - up until now they have been MS Excel, but am trying to convert to MatLab. One of my issues at the moment is producing quality reports after the user has entered the necessary data. My question is is it typical to have a separate .m file to produce the report that is run in the background from the primary GUI?

Try using OfficeDoc to generate reports on Word, PowerPoint and/or Excel (it works using COM): http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc-read-write-format-ms-office-docs-xls-doc-ppt

> Also, on a side note, does anyone know if MathWorks will ever institue a real multitab interface?

http://UndocumentedMatlab.com/blog/tab-panels-uitab-and-relatives/

Yair Altman
http://UndocumentedMatlab.com

Subject: Report production when Using a GUI

From: Arnaud_Miege

Date: 2 Nov, 2010 10:36:22

Message: 10 of 13



"Jeff " <jagymg@yahoo.com> wrote in message
news:iamts0$5ht$1@fred.mathworks.com...
> I typically use GUI's for many of my projects - up until now they have
> been MS Excel, but am trying to convert to MatLab. One of my issues at the
> moment is producing quality reports after the user has entered the
> necessary data. My question is is it typical to have a separate .m file to
> produce the report that is run in the background from the primary GUI?
>
> Also, on a side note, does anyone know if MathWorks will ever institue a
> real multitab interface?
>
> Thanks,
> Jeff

Also have a look at GUI layout toolbox:
http://www.mathworks.co.uk/matlabcentral/fileexchange/27758-gui-layout-toolbox

HTH,

Arnaud

Subject: Report production when Using a GUI

From: Eric

Date: 2 Nov, 2010 17:09:05

Message: 11 of 13

"Jeff " <jagymg@yahoo.com> wrote in message <ianlfn$gs1$1@fred.mathworks.com>...
> Eric,
>
> Thanks so much for your help. Typically I like to present data in tables. Initially, I was thinking Word, but them relaized I should stick with Excell. I am very familiar with Excel VBA, but not Word. I started to look at Word VBA today, but did not like the format. So I'll probably go back to Excel as the depository for current data and report printing. Kinda of weird though using Excel just for printing. Guess that allows me to simply insert data into a certain cell easily unlike what I imagine it would take to do the same think in Word.
>
> Is it just me or does it seem like MatLab just doesn't provide enough documentation on the various options and functionality of its publishing routines?
>
> Thanks again Eric for your help.
>
> Jeff

I don't know a lot about the publishing documentation. I generally haven't used publishing in Matlab that much. I did try it again last week as a colleague was talking about how he uses Mathcad for some analyses because of its formatting capabilities. I tend to do the same. I thought I'd take a look at the publishing tools again. Publishing to HTML looked pretty good, but that's a bit of a pain since it puts things in multiple documents. I switched to publishing in Word and was aghast at how poor the document looked.

I use Excel from Matlab rather frequently as well. You can use the built-in xlsread() and xlswrite() for simple things, but you can also use the Excel COM interface from Matlab as well. You can generate rather professional-looking spreadsheets this way. You can do things like adjust formatting of text, formatting of numbers, merge-and-center, adjust column widths, insert equations, etc. that xlswrite() doesn't permit. You can look at the code for xlsread() and xlswrite() to get started. There are also some useful functions in there for working with ranges as well.

-Eric

Subject: Report production when Using a GUI

From: Jeff

Date: 3 Nov, 2010 02:47:04

Message: 12 of 13


> Also have a look at GUI layout toolbox:
> http://www.mathworks.co.uk/matlabcentral/fileexchange/27758-gui-layout-toolbox

Awesome toolkit. Will definitely have a look. Thanks.

Subject: Report production when Using a GUI

From: Jeff

Date: 3 Nov, 2010 02:48:05

Message: 13 of 13

> Try using OfficeDoc to generate reports on Word, PowerPoint and/or Excel (it works using COM): http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc-read-write-format-ms-office-docs-xls-doc-ppt
>
> > Also, on a side note, does anyone know if MathWorks will ever institue a real multitab interface?
>
> http://UndocumentedMatlab.com/blog/tab-panels-uitab-and-relatives/
>
> Yair Altman
> http://UndocumentedMatlab.com

Thanks for the references. I'll look these up.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us