Back to homepage
Matlab Tips
Contents:
Unix C-shell Script
Save the following script in a file, say matlab-in-background, and make it executable:
#!/bin/csh -f
unsetenv DISPLAY
nohup matlab < $1 > $2 &
Usage
Run the command:
matlab-in-background [input] [output]
where [input] is the script file to run by matlab, and [output] is the file to which the output should be dumped into.
functions on a field in an array of structures
Assume a structure, e.g., packet, with the fields
packet.arrivalTime
packet.departureTime
Assume an array of structures, e.g., traffic, where for every i, traffic(i) is a packet.
To compute a function of one of the fields, over all structures in the array, use the cat() function. E.g., in order to compute the maximum arrival time of a packet in the traffic, use:
max(cat(1,traffic.arrivalTime))
This concatenates the values of the field arrivalTime of all entries in the traffic structure array into a 1-dimensional matrix, thus enabling running the max() function on the array of reals.
plotting a function parameterically, quickly
To plot the function f(x)=x/(1+x) in the domain [0,1], use
f = @(x) x./(1+x);
ezplot(f,[0,1]);
This makes use of the Symbolic Toolbox (see online documentation for further info).