Wednesday, March 11, 2009

Some MATLAB Tricks

These are some MATLAB tricks I will be compiling over time.

  1. Use get(0,'ScreenSize') to get screen size, and use figure('OuterPosition',[left bottom width height]) to set figure size and location.
  2. Use dynamic fields name in structs instead of eval commands. Ex: Instead of eval(['a.', 'first', '=', i]); use str = 'first'; a(str) = i;
  3. Use cells to create multi-line titles. Ex: plot(1:10), title({'First Line','Second'}) 
  4. Use uitable to visualize some matrices. Ex: a = uitable, set(a,’data’, magic(3))
  5. Use isequal to compare arrays for equality.
  6. Use hold all to hold subsequent plots and automatically switch line color and marker styles.
  7. To set marker every N lines, draw three plots. h = plot(NaN,NaN,'b-*',x,y,'b-',x2,y2,'*'); legend(h(1),'signal');
  8. Close all figures including GUI's with close all hidden . Note that if the HandleVisibility of a GUI is set to off or callback, it cannot be closed by close all only, the extra parameter 'hidden' is needed in this case.

Also, see the MATLAB questions at StackOverFlow.

No comments: