I am developing a Matlab application for myself and for others using a GUI on Excel (for ease of use but also because some data processing need to be done in Excel).
To simplify, here are all the parts making up my application:
Part 1: Excel GUI with run settings
Part 2: Matlab program creating data results and images
Part 3: Excel GUI with Matlab data & image results and aditionnal Excel data processing
Currently, when others need to use it, they give me the run settings (Part 1), I run the Matlab program for them (Part 2) and give them the data, images and my last Excel GUI (Part3).
I am trying to improve the situation by combining the parts above. I see 2 options:
Option 1: Running Matlab from Excel (Spreadsheet Link EX Toolbox) therefore having Part1 & Part2 together
=> would be more for me (I have Matlab, and I can see more info from running my Matlab code)
Option 2: Packaging it all: Part 1+2+3 in an executable (MATLAB Compiler Toolbox)
=> would be for my end users (no Matlab needed)
Now my questions:
Can I (Should I? Should I not?) do both options? or am I over complicating everything? and should not use Excel Link toolbox at all?
Do I need Matlab Builder EX to achieve Option 2? (therefore creating an Add-in) or could I also achieve this with the toolboxes: Excel Link + Compiler? (No Add-in, but VBA code?)
Cheers!
If you choose to use the MATLAB Compiler, the following is what I imagine the steps would be
create a GUI in MATLAB. It will present an interface that allows the user to input some settings. It also has a "RUN" button that will run your MATLAB program with those parameters.
at the end of your alorithm, use COM automation to open Excel and programmatically fill tables with the results of the previous step. You could add snapshots of any generated MATLAB figures and plots to the excel file (see here for an example) or simply save as separate image files. You could even add VBA macros to the sheet.
Deploy the above as a standalone application. It will not depend on MATLAB (only the freely available MCR runtime has to be installed by the user).
The user runs your application, and use it to generate the Excel file. Now the user can optionally open this file, and manually perform any final data manipulation.
If you want additional integration, you could use the "Spreadsheet Link EX" toolbox.
HTH
There is a great answer which kind of answer my question.
MATLAB Compiler vs MATLAB Coder
Basically:
For R2014b and ealier version: It is possible to produce Excel add-ins with the "MATLAB Builder EX for Excel" toolbox
From R2015a (recent release): The toolbox "MATLAB Compiler" can now produce Excel add-ins
This simplify things a lot!
Nico (answering his own question :-) )
Related
Is there a difference from running the same exact Maple commands to export a plot, when run from GUI interface, using worksheet, vs. from plain text .mpl file using command line Maple?
The following code runs OK from the GUI worksheet, but gives error
Error, invalid FONT specification when run from cmaple.exe.
This is on windows 10.
#file T1.mpl
currentdir("C:/TMP"); #or any other folder of your choice
plotsetup(default); #start from default
#the following commnad below export a plot to a file
plotsetup(ps, plotoutput="t.ps",
plotoptions=`color,noborder,portrait,height=250`);
p0:=DEtools:-DEplot( diff(y(x),x)=x, y(x), x=-2..2, y=-2..2,
'color' = "#00aaff",
'arrows'='medium',
'labels'=["",""],
'thickness'=1
):
#this will send the plot to a file.
print(plots:-display([p0],'view'=[-2..2.4,-2..2.5],
axis=[tickmarks=['color'='red']],
font=["Times",bold,8]
)
);
#ERROR SHOWS HERE
plotsetup(default); #rest back to default
The print command above, does not actually display anything, even on the GUI, since it was redirected to go to a file.
The above code works with no problem in the GUI interface, and the plots is exported OK to t.ps file.
I am trying to run the large Maple code I have from .mpl using command line Maple, hoping it will be faster than in worksheet, but the above problem is making it not possible.
First time trying cmaple.exe
Command I used is
"C:\Program Files\Maple 2018\bin.X86_64_WINDOWS\cmaple.exe" T1.mpl
May be I need an option to add to the command above?
This is using Maple 2018.1
The plot export driver in the Commandline Interface (CLI, aka TTY) does not know about the more modern calling sequences allowed for the various font related plotting options.
In modern Maple the font options can be specified using strings instead of names. That helps users avoid issues with assigning to alternative all-caps name forms, not all of which are protected names.
Unfortunately, it seems as if the CLI plot export driver does not know about the newer string forms. I will submit a bug report.
But you can still use the older, all-caps, name form.
Replace,
font=["Times",bold,8]
by,
font=[TIMES,BOLD,8]
Back when I was quite current with Maple, the answer to this question would have been: the GUI and the TTY version use different plot drivers. And the TTY plot drivers are not as well maintained as the ones for the GUI, and so more recent features do not always work for them.
I am guessing that this is still the case, and that the TTY plot driver doesn't know about fonts.
Is there a way to fold sections of codes in Live Scripts as there is in regular scripts?
I have tried to look for it in the preferences and enabled all kind of foldings, but none of them relate to the Live Scripts. I would expect it to work since the notation of %% is similar in both types of scripts.
Any idea how to enable/workaround this?
No, I don't believe you can do this. Seems like a nice thing to want to do, though, so I would enter an enhancement request with MathWorks. I have no suggestion for a workaround, I'm afraid.
I know this is old but in case anyone else is wondering, below are the workarounds suggested to me by tech support when I submitted an enhancement request. I encourage the reader to add their vote by submitting a request if they still want to see this feature added to the live editor.
Convert to M file and "publish" with 'showcode' as false. First, convert the Live Script into an M file. You can do this interactively
by clicking "Save As" and then choosing the "M" file option in the
File Type section or you can do it programmatically as follows:
>> matlab.internal.liveeditor.openAndConvert('live_script_to_be_converted.mlx',
'output_script.m');
Once you have the converted M file which has all the section breaks
and formatting, you can use the "publish" function as follows from the
MATLAB Command Window:
>> options.format = 'pdf';
>> options.showCode = false;
>> publish('output_script.m',options)
This will publish the PDF file to a sub-directory called "html" inside
the current working directory.
Here is a documentation link for the "publish" function and
specifically, the "showCode" option:
https://www.mathworks.com/help/matlab/ref/publish.html#input_argument_namevalue_d119e823467
Please note, when saving the MLX file as M file and then publishing,
it does not convert the LaTeX expressions to something readable. It
also automatically inserts a table of contents at the beginning.
Encapsulate the code in another script or function. An alternate approach would be for you to encapsulate the code you want to hide in
another script or function and call it from your published Live
Script. For example, something like:
>> %% Now plot a figure
>> functionThatPlotsAFigure
In this case, instead of publishing all the plotting code, only the
call to the plotting function would be published.
Publish the Live Script as an HTML and then modify the HTML page to hide the code sections and then publish it as a PDF.
The options stated above are simply workarounds as we do not currently have this functionality. A request has been submitted to our developers to add in this feature and they are considering this for future releases of MATLAB. We appreciate your feedback as we constantly strive to improve our products.
in a textbook, examples on the book companion website are given in Maple, using a .mws file format.
I do not have Maple but I am interested in studying the code of the examples.
I wonder if there is a conversion tool for Linux that allows me to export to text or at least to view the content of the script.
I am aware there exist a free Maple player but from the product description it is not clear if it allows to see the script content or just "play" with the inputs it defines.
I did also try this Maple-to-Python converter, but it's very alpha and it just doesn't work.
The Maple Player should definitely be able to open any .mws file. You won't be able to run commands, but you can at least read the code contained in the file.
Maple itself can export .mws files to text, but other than that, I haven't heard of any other converters for extracting the code from these files.
I am using a MATLAB script to tune the control system on a machine. When the tuning is complete, I would like a report containing text (especially serial number, date/time and the values determined during tuning) and plots, especially transfer functions.
What do to you recommend?
Whatever solution I use should be compatible with the MATLAB compiler so I can distribute my solution to a team of field engineers.
Ideally the report will be a PDF document.
The MATLAB report generator does not seem to be the right product as it appears that I have to break up my script into little pieces and embed them in the report template. My script contains opportunities for the user to intervene and change values or reject the tune if plots don't look right and my hunch is that this will be difficult if the code runs from the report generator. Also, I fear code structure and maintainability will be lost if the code structure is determined by the requirements of the report template.
Please comment if my assumptions are wrong.
UPDATE
I have now switched to use the MATLAB Report Generator with release r2016b and it is working very well for my compiled code users. Unfortunately it means that colleagues who have a MATLAB licence need to buy the Report Generator too, to use my tools scripted.
As the MATLAB Report Generator's development manager, I am concerned that this question may leave the wrong impression about the Report Generator's capabilities.
For one thing, the Report Generator does not require you to break a script up into little pieces and run them inside a template. You can do this if you choose and in some circumstances, it makes sense, but it is not a requirement. In fact, many Report Generator applications use a MATLAB script or program to interact with a user, generate data in the MATLAB workspace, and as a final step, generate a report from the workspace data.
Moreover, as of the R2014b version, the MATLAB Report Generator comes with a document generation API, called the DOM API, that allows you to embed document generation statements in a MATLAB program. For example, you can programmatically create a document object, add and format text, paragraphs, tables, images, lists, and subdocuments, and output Microsoft Word, HTML, or PDF output, depending on the output type you select. You can even programmatically fill in the blanks in forms that you create, using Word or an HTML editor.
The API runs on Windows, Linux, and Mac platforms and generates Word and HTML output on all three, without the use of Word. On Windows, it uses Word under the hood to produce PDF output from the Word documents that it generates.
The latest release of the MATLAB Report Generator introduces a PowerPoint API with capabilities similar to the DOM API. If you need to include report generation in your MATLAB application, please don't rule out the MATLAB Report Generator based on past impressions. You may be surprised at just how powerful it has become.
I've done this quite a bit. You're right that MATLAB Report Generator is typically not a great solution. #Max suggests the right approach (automating Word through its COM interface), but I'd add a few extra comments and tips, based on my experiences.
Remember that if you're going with this solution, you are depending that your end-users will be running Windows, and have a copy of Office on their machine. If you want to ultimately produce a PDF report, that will need to be Office 2010 or above.
I would bet that you'll find it easier to automate the report generation in Excel rather than Word. Given that you're producing a report from MATLAB, you'll likely be wanting quite a lot of things in tables of numbers, which are easier to lay out in Excel.
If you are going to do it in Word, the easiest way is to first (without MATLAB) create a template .doc/.docx file, which contains any generic text that will be the same for all reports and blank tables for any information. Turn on track changes, and insert empty comments at each point that you will be filling in information. Then within your report creation routine in MATLAB, connect to Word and iterate through each comment, replacing it with whatever data you wish.
If you are learning to automate Excel from MATLAB, this page from the Excel Interop documentation is really helpful. There's an equivalent one for Word.
Unlike #Max, I've never had good results by saving figures to an .emf file and then inserting them. In theory that does preserve editability, but I've never found that valuable. Instead, get the figure looking right (and the right size) in MATLAB, then copy it to the clipboard with print(figHandle, 'dbitmap') and paste to Excel with Worksheet.Range('A1').PasteSpecial.
To save as a PDF, use Workbook.ExportAsFixedFormat('xlTypePDF', pathToOutputFile).
Hope that helps!
I think you are right about the report generator.
In my opinion the fastest/easiest approach would be to generate the report in a html document. For that you just need the figures and write a text file, conversion should be trivial.
Quite similar approach would be to create a Latex file. And then create a pdf from it - though for this you'd need to install latex on your deployed machines.
Lastly you could use the good integration of Java in Matlab. There are several libraries you could use - like this. But I wonder if all the complication will be worth it.
Have you considered driving Microsoft Word through its ActiveX interface? I've done this in compiled Matlab programs and it works well. Look at the Matlab help for actxserver(): The object you want to create is of type Word.Application.
Edit to add: To get figures into the document, save them as .emf files using the -dmeta argument to print(), then add them to the document like this:
WordServer.Selection.InlineShapes.AddPicture(fileName);
I'm using Matlab and need to get an ASAP2 (a2l) file exported from a Simulink model, using the Real-Time Workshop toolkit, from the command-line so it can be run as part of a batch operation.
I know that the process is possible by following the standard procedure for generating an ASAP2 file from a model, via the GUI, but this is no use to me in this instance as it requires user interaction with the GUI.
I've scoured Google and the Mathworks forums for an answer to this one but have come back with nothing; so does anyone know the command to generate an a2l file from the Windows CLI?
Thanks for any help you can offer.
Is the a2l file being generated when you press Build or Generate Code on the GUI? If so, the command-line equivalent is
rtwbuild(model);
Re-reading your question, I think you might be asking how to generate the file from a Windows command prompt. You can startup MATLAB and have it run any command using the -r option,
% matlab -r "load_system('model'); rtwbuild('model'); quit;"
Or you can write a a script to do all this, and call that script.