Some avi files generated from Matlab are missing indexes and can’t be opened by avidemux. Use mencoder to fix.
mencoder -idx -oac copy -ovc copy infile.avi -o outfile.avi
You are currently browsing the archives for the Matlab category.
Some avi files generated from Matlab are missing indexes and can’t be opened by avidemux. Use mencoder to fix.
mencoder -idx -oac copy -ovc copy infile.avi -o outfile.avi
I’ve just discovered that you can select outliers in a plot and remove them from the underlying data set quite easily.
Say you have data in 3 columns (time, x and y).
plot(data(:,2), data(:,3), 'r*-'); brush on; %button with brush linkdata; %button with chain link
Then you can select points and right click to remove them or save them to another variable.
Each data item must be a line as in the example above because brushing seems to select entire lines of data rather than columns.
Hitting the delete key will not remove data but will replace the whole line with NaN. In the example this includes the timestamp which wasn’t plotted.
This has only been available since Matlab 7.6.0 (R2008a). Very useful.
An article on MatlabCentral.
The Matlab documentation about data brushing and data linking.
When producing camera ready versions of publications it seems best to create a Postscript file and then convert to PDF. Some printers (printing companies) require the Postscript files and it’s also the only way I’ve found to correctly embed all the fonts in the PDF.
In Matlab I’ve been using set(gcf, 'PaperPositionMode', 'auto'); print -depsc myfigure.eps; to create the eps file for including in LaTeX.
Run latex mypaper.tex to produce the dvi file.
Run dvips -Ppdf -G0 -tletter mypaper.dvi to produce the PS.
Run ps2pdf -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=letter mypaper.ps to produce the final PDF file. Use pdffonts mypaper.pdf to check that all fonts are correctly embedded.
Replace letter with a4 in the dvips and ps2pdf commands if you’re publishing for Europe.
Some useful links:
Here is a Matlab implementation of the Douglas-Peucker polyline simplification algorithm. It takes a polyline and removes as many vertices as possible without changing the shape too much. This code is ported from the C++ version at SoftSurfer. I’ve included some sample data to test the function.
EDIT: I just found a Python implementation which is iterative rather than recursive, unlike the Matlab one. It’s based on a freely-licensed C++ implementation.
Sometimes Matlab exports figures as PDFs with the graph overflowing from the page. This can be fixed by using the orient landscape or orient portrait commands. Exporting to PDF from the command line can be done with print('-f1', '-dpdf', 'my-plot.pdf');.
There were a few days when Matlab would freeze whenever I tried to open the plot tools or add a legend to a figure. It turned out that this was an OpenGL issue which I fixed by updating my fglrx graphics driver (I’m afraid I can’t remember the details). During that time I still wanted to edit figures but because the plot tools weren’t working I had to use the command line. This is possible but you need to know the handle of each object that you want to modify. The findall command is useful for this. Once you have the handle the get and set commands let you modify properties.
For example if I want to add some circle markers to a figure:
>> h = findall(gcf, 'type', 'line')
h =
159.0101
>> get(h)
DisplayName: ''
Annotation: [1x1 hg.Annotation]
Color: [0 0 1]
EraseMode: 'normal'
LineStyle: '-'
LineWidth: 0.5000
Marker: 'o'
MarkerSize: 6
MarkerEdgeColor: 'auto'
MarkerFaceColor: 'none'
XData: [1x19 double]
YData: [1x19 double]
ZData: [1x0 double]
BeingDeleted: 'off'
ButtonDownFcn: []
Children: [0x1 double]
Clipping: 'on'
CreateFcn: []
DeleteFcn: []
BusyAction: 'queue'
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'on'
Selected: 'off'
SelectionHighlight: 'on'
Tag: ''
Type: 'line'
UIContextMenu: []
UserData: []
Visible: 'on'
Parent: 158.0101
XDataMode: 'manual'
XDataSource: ''
YDataSource: ''
ZDataSource: ''
>> set(h, 'Marker', 'o')
The MathWorks have documented all of this.
Reversing the elements of a vector in Matlab can be done with X(end:-1:1). The end keyword is also useful for accessing the last element of a vector instead of using size or length.
When I tried to print a figure or some code from the File > Print menu or by clicking the Print button, I got a popup saying There are no properly configured printers on the system. This is on a GNU/Linux system running CUPS. Strangely the print command worked fine from the command line.
There is apparently a CUPS related bug in Java. I applied a workaround and set all my printers to portrait orientation. This allowed me to print from other Java applications such as Netbeans but still not from the Matlab GUI.
In the end the problem was another CUPS related bug in Java which can be solved by commenting out a line in /etc/cups/cupsd.conf like this:
Listen localhost:631
#Listen /var/run/cups/cups.sock
The guy from the MathWorks support team was very helpful and patient. Here is the e-mail that helped me solve the problem, I hope he doesn’t mind me posting it here. Although only point 5 was required in my case the other items may be useful for others.
Read more…
Matlab exports figures as PDF files with very large borders. This can be magically fixed with a small Perl script called pdfcrop.