[ TOP ] | [ LaTeX Tips ] | [ MATLAB Tips ] | [ HSPICE Tips ] | [ SwitCap2 Tips ]

Matlab Tips

[TOP of This page]

Before invoking ...

Matlab Helpdesk
I don't believe this info is not so popular in ECE/ORST but you can access Matlab helpdesk in ECE. Matlab Helpdesk is a place which has all help files in HTML and the manual in PDF
  1. Go to ECE Computing page
  2. Choose "Matlab documentation".
  3. You will be asked user name and password. Those are the same as the login name and the password of ECE network. This may be stored in cockies and you may not be asked again. Yod don't know what cockies are? Never mind. :-)
  4. Once after you could acess it, you will find help desk here.
  5. Again it has manuals in PDF under each toolbox ref.
Usefull pages: In this case, you don't need any membership, of course, if you're in ECE.

Your matlab directry
You can put your favorite function in your matlab directry under your home directry. Matalb search your ~/matlab when you invoke matlab automatically.

Be nice!
ECE recommends us to use "nice" command with matlab. I have the alias in my .cshrc.user file.
alias mat 'nice matlab'

For emacs lover
You can download an emacs lisp of the matlab-mode from Mathworks web site.

Running in background
You can run your M-file in your shell script with redirection method. Consider this when you need, especially mid-night working. :-)
% nice matlab < foo.m > result.txt
More info in Mathworks.

Data clip
Some hints are in Mathworks web site. But I would use awk/sed to create a pure data file.

[TOP of This page]

String Tips

Combine two strings
       ss3=[ss1 ss2]

       smat=[{ss1}, {ss2}, {ss3}]
Making the file name which has string + number
       %string test
       ss3=[ss1 ss2]
       smat=[{ss1}, {ss2}, {ss3}]
       for m=1:3
         fprintf(fid,'This file is for %s\n',smat{m});
[TOP of This page]

Transfer function

Getting NUM and DEN from 'tf' format

       [NUM, DEN]=tfdata(H);
       HB=NUM{1}; HA=DEN{1};

Alternatively and simply,

       [HB, HA]=tfdata(H, 'v');

(thanks to Péter)
[TOP of This page]

File I/O

Input your file name

       celar all
       R = input('What is the data file name? : ', 's')
       dd = load (R);
       % you need '(' and ')'. That's a tip!
       in1 = dd(:,1);
[TOP of This page]

FFT Tips

FFT calculation
We have to multiply some coefficient to adjust the result of MATLAB fft.
       Sample code to get the correct power:
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% initialization
       N = 1024;		% Total number of samples
       As = 1;			% Signal amplitude
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sine signal
       st = As * sin(2*pi*100*[0:N-1]./N);
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fft
       Sf = fft(st);
       Sf = Sf .* conj(Sf);
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Normalization
       % * 2 is for imaginary and real freq.
       % N^2 to get -3dB for the amplitude of one
       Sf = Sf * 2 / N^2;		
       plot(10*log10(Sf)); grid
[TOP of This page]

Figure Tip

Index of subplot: (a), (b), ...
Under the xlabel, the index of subplot is sometimes needed, which means (a), (b), and so on. It was very easy. Try
xlabel({'frequency in Hz';'(a)'})

For more info, please refer this. Solution Number: 1405 How can I place a two-lined title, x-label, y-label, or z-label on my plot?

How to use " ' " in the figure title
Matlab complains if you use the " ' " character. I'm cheating. Try LaTeX \prime command instead of typing " ' ". For example,
title('This is Kajita{\prime}s plot')

[TOP of This page]


I don't get the solution yet. But you may refer to Tech Note: 1608 and thisin Mathworks. Then, tell me how to do that, when you find out...

Here is what I am trying so far:

  1. Compile C-Mex code using
    % cmex -g foo.c
  2. Run matlab with the option:
    % matlab -Dgdb
  3. Use run command in the debugger:
    (gbd) run
  4. There are lots of messages on the screen and it stopped.
  5. Enforce the debugger in the front:
    % fg
  6. Press to continue.
  7. Matlab opening window is shown, but stopped again.
  8. Type run again:
    (gbd) run
  9. Type y to start it from the beginning.
  10. Type to continue.
  11. Now I get Matlab prompt.
  12. Enable MEX-file debugging:
    >> dbmex on

[ TOP ] | [ LaTeX Tips ] | [ MATLAB Tips ] | [ HSPICE Tips ] | [ SwitCap2 Tips ]
Comments? Email to Testuya Kajita

Last modified: Thu Oct 19 11:48:11 2000