Showing posts with label matlab. Show all posts
Showing posts with label matlab. Show all posts

Matlab's cryptic error messages

May 17, 2014
Sometimes MATLAB's error messages can be very cryptic and misleading. Following are examples of error messages which I encountered while trying to solve \(\mathbf{A}x=b\) in least square sense using MATLAB's lsqr function. %% Error 1 Error using iterapp (line 60) user supplied function ==> @(x,transp_flag)transform_X(x,transp_flag, ...) failed with the following error: Not enough input arguments. Error in lsqr (line 180) u = u - iterapp('mtimes',afun,atype,afcnstr,x,varargin{:},'notransp'); %% Error 2 Error using * MTIMES is not supported for one sparse input and one single input. Error in iterapp (line 29) y = afun * x; Error in lsqr (line 180) u = u - iterapp('mtimes',afun,atype,afcnstr,x,varargin{:},'notransp'); For an experienced MATLAB user, error 2 may be easier to locate because of the message: "Error using *". However, when I was actually working, I got error 1 which said "Not enough input arguments". It took me sometime to figure out that both the errors were related to mismatching datatypes in input parameters. Both the situations were actually identical, except that in first case I was using function handle Afun in place of matrix representation of \(\mathbf{A}\). Here are the actual statements which raised errors: x = lsqr(Afun, b, 1e-9, 100, [], [], x0); % Raises Error 1 x = lsqr(A, b, 1e-9, 100, [], [], x0); % Raises Error 2
And here is the code snippet for Error 2 above. The code can be modified easily to create function handle Afun (see Example 2 here). Notice the statement x0 = single(rand(size(b))*5); in the code snippet which changes the datatype and causes error. n = 50; on = ones(n,1); A = spdiags([-2*on 4*on -on],-1:1,n,n); b = sum(A,2); x0 = single(rand(size(b))*5); x = lsqr(A,b,1e-9,100,[],[],x0);
The take-away message: Always check datatypes when MATLAB's error messages don't make sense!
Read more ...

Matlab Font(s) - Windows

Jan 14, 2011
I do not find Matlab default font to be soothing to eyes, specially the fonts in figure windows. See more about fonts here. So, here are the instructions to change the fonts in matlab. Make sure that you have installed the font of your choice.
  • For editor, main window, GUI
    Navigate to File->Preference. Select "Fonts" in the left panel. Then follow the instructions over there. You can also check the 'Custom' tab for advanced settings.
  • For figure window
    Add following lines to your startup.m. See next section for details. set(0,'DefaultAxesFontName','DejaVu Sans'); set(0,'DefaultAxesFontSize',10); set(0,'DefaultAxesFontWeight','Bold'); set(0,'DefaultTextFontName','DejaVu Sans'); set(0,'DefaultTextFontSize',10); set(0,'DefaultTextFontWeight','Bold'); Change the font-name & size according your choice. You can find a list of installed fonts by typing following command at matlab prompt. listfonts
startup.m
Each time matlab is started, it searches all the matlab path for this file. The most common place to keep this file is: C:\Users\<user-name>\Documents\MATLAB\ This is good place to put/over-ride settings. Create this file, if it is not present.

I am having hard-time  to configure the same thing in Ubuntu. I will be posting the same, if I get some success.
Update: I was not able to get anti-aliased fonts in linux. But, I found a font called 'Andale Mono', which gives good result with aliased fonts. This link might help in some cases.
Read more ...