time
command. For example
>time ls
>real 0m0.006s
>user 0m0.001s
>sys 0m0.004s
Command
time ls
measures time used by ls
program.
i.e. some stuff and junk about Python, Perl, Matlab, Ruby, Mac X, Linux, Solaris, ...
time
command. For example
>time ls
>real 0m0.006s
>user 0m0.001s
>sys 0m0.004s
time ls
measures time used by ls
program.
function [rect_1 rect_2 point]= getRects(filename)
rect_1=[];
rect_2=[];
point=[];
fid=fopen('rectangles.txt');
while true
tline = fgetl(fid);
if tline(1)=='#', continue;end;
if ~ischar(tline), break, end;
[file,theRest] = strtok(tline);
if ~strcmp(file,filename), continue; end;
RECTs= sscanf(theRest,'%f')';
rect_1=RECTs(1:4);
rect_2=RECTs(5:8);
point=RECTs(end-1:end);
end
fclose(fid);
tic;getRects('105aty.tiff'); toc;
combination in Matlab both for full Matlab script and Matlab/Perl script. Each script was tested 100 times.perl
function:Perl is included with MATLAB on Windows systems, and thus MATLAB users can run M-files containing the Perl function. On Unix systems, MATLAB just calls the Perl interpreter that's available with the OS - from Matlab help.This function can save a lot of work, and make working with files in Matlab very fast, and convenient; in fact, as convenient as Perl is. At the same Matlab page we read:
It is sometimes beneficial to use Perl scripts instead of MATLAB code...Indeed, it is very beneficial, especially if one works for example with text files and further in this post I am going to show one example how Perl can be used withing Matlab while working with txt files.
[rect_1 rect_2 point] = getRects('001anv.tiff');
%GIVES:
rect_1 = [113 302.5 49.035541 58.514286];
rect_2 = [274 292.5 90.87837491 89.96484776];
point = [5.220703 4.375];
function [rect_1 rect_2 point]= getRects(filename)
%execute Perl script
a=perl('getRectPos.pl',filename,'rectangles.txt');
eval(a); %evaluate string returned from Perl
eval(a)
operation. As described in my former post, Perl returns string representing its standard output. Hence, in order to get Matlab data structures and variables from Perl, it is required to return them as strings, and then execute that string using eval
function.
#File: getRectPos.pl
#Read arguments from Matlab
my $fileName = $ARGV[0];
my $fileWithRect = $ARGV[1];
#create piece of Matlab code - declaration
#of variables.
my $out="rect_1=[]; rect_2=[]; point=[];";
my %goldHash=&readFileToHash(
$fileWithRect
);
if ( exists $goldHash{$
fileName
}) {
my @r1 = @{$goldHash{$key}}[0..3]; #(x,y,w,h)
my @r2 = @{$goldHash{$key}}[4..7]; #(x,y,w,h)
my @p = @{$goldHash{$key}}[-2..-1]; #(x, y)
#create the rest of the Matlab code to be executed by eval
foreach my $v (@gmROI) { $out .= "Med(end+1)= $v; "; }
foreach my $v (@glROI) { $out .= "Lat(end+1)= $v; "; }
foreach my $v (@scales) { $out .= "Scales(end+1)= $v; "; }
}
#print string to Matlab
print $out;
sub readFileToHash {
#read file values to a hash table
#key value in this hash is file name (first column)
#data is all the rest columns: 2-12
my $fname = shift;
my %temp=();
open(FG,"<$fname") || die "Cannot find file ",$fname; while () {
chomp;
my ($k,my @rec) = split('\t',$_);
$temp{$k}=[@rec];
}
close FG;
return %temp;
}
a=
rect_1=[];rect_2=[];point=[];rect_1(end+1)= 104.000000; rect_1(end+1)= 303.000000; rect_1(end+1)= 49.035541; rect_1(end+1)= 58.514286; rect_2(end+1)= 282.964459; rect_2(end+1)= 294.000000; rect_2(end+1)= 49.035541; rect_2(end+1)= 58.514286; point(end+1)= 5.220703; point(end+1)= 4.375000;
evel(a)
, in Matlab environment all required vectors are created (rect_1,rect_2,point).message_size_limit = 20240000
(&myFun1 &myFun2)
to the special, per-package array @EXPORT
. When someone imports this module, variables and functions listed in that array are aliased into the caller's own package. That way they don't have to call the function Utilities::MyModule::
myFun1()
after the import. They can just write shuffle(23)
instead. This won't happen if they load Utilities::MyModule with require
Utilities::MyModule; only a use
imports.Lines 5 and 8 set up the package global functions to be exported.
1
, indicating the overall return value of the module. If the last evaluated expression in the module doesn't produce a true value, an exception will be raised.Java exception occurred:
java.lang.OutOfMemoryError: PermGen space
So I did a little of the Internet browsing and I found out that the solution to that problem was to create file java.opts in my working directory. In this file, one can put all options to java virtual machine. To increase my memory amount i had to put there:
-Xms128m
-Xmx128m
-XX:PermSize=128m
-XX:MaxPermSize=128m
Only with that option, my Matlab 7.0 and my java program worked. I also tried solution at official matlab site: here. But it didn't work. I had to use all four parameters in order to run my program.
The solution to my problems was to add to the end my Xemacs configuration file (Users/my_user_name/.xemacs/init.el) following lines:
(define-key global-map 'button4
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-down 5)
(select-window curwin)
)))
(define-key global-map [(shift button4)]
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-down 1)
(select-window curwin)
)))
(define-key global-map [(control button4)]
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-down)
(select-window curwin)
)))
(define-key global-map 'button5
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-up 5)
(select-window curwin)
)))
(define-key global-map [(shift button5)]
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-up 1)
(select-window curwin)
)))
(define-key global-map [(control button5)]
'(lambda (&rest args)
(interactive)
(let ((curwin (selected-window)))
(select-window (car (mouse-pixel-position)))
(scroll-up)
(select-window curwin)
)))
This is what I was looking for, and what's the most important - it worked.
In addition to that, I did exactly the same thing to my XEmacs on my Solaris server (I use X11 to work remotely on Solaris from my Mac). It worked also.
Ruby comes with overloaded operator &, using which intersection of two array is childish.
For example:
#!/usr/bin/env ruby
a=[1, 2, 3, 4]
b=[1, 2, 2 ,3 ,4, 5, 6]
c= a & b #intersection of 'a' and 'b' arrays
print c
will produce: 1 2 3 4
And for example this:
#!/usr/bin/env ruby
a=['aa', 'ac', 'acb', 'acbd']
b=[ 'ac', 'acb', 'bca', 'zwx']
c= a & b #intersection of 'a' and 'b' arrays
puts c
will produce: ac acb
Everything is OK, when you perform intersection of standard types, like String or Integers, etc.
However, there is problem when you create your own class, and try to perform intersection of array of objects of your class.
#!/usr/bin/env ruby
class MyClass #my own very simple class
attr_reader :var1, :var2
def initialize(arg1,arg2)
@var1 = arg1
@var2 = arg2
end
def to_s
"#{var1}: #{var2}"
end
end
a = [MyClass.new('house',3), MyClass.new('mouse',5)]
b = [MyClass.new('cat',3), MyClass.new('house',5), MyClass.new('mouse',5)]
c = a & b #INTERSECTION !!!
puts c
This, unfortunately gives nothing!
After a while I found solution to that. The solution is: you must overload eql? and hash functions in you class. Java programmers should now something, because as I remember in Java, you do something similar while working especially with Comparable interface.
So, to make intersection, final example my program looks like this:
#!/usr/bin/env ruby
class MyClass attr_reader :var1, :var2
def initialize(arg1,arg2)
@var1 = arg1
@var2 = arg2
end
def to_s
"#{var1}: #{var2}"
end
def eql? other #OVERLOADED eql? !!!
other.kind_of?(self.class) && @var1 == other.var1
end
def hash #OVERLOADED hash !!!
@var1.hash #use var1 hash value,
#as hash for MyClass
end
end
a = [MyClass.new('house',3), MyClass.new('mouse',5)]
b = [MyClass.new('cat',3), MyClass.new('house',5), MyClass.new('mouse',5)]
c = a & b #INTERSECTION !!!
puts c
house: 3
mouse: 5
I used only standard hash value from @var1 in my class, because I was only interested in making intersection based on @var1, nevertheless there is noting against to make more complex hash and eql? function.
To setup nfs server on you Ubuntu, few steps are required.
showmount -e localhost
and if you see:
Export list for localhost:
/home/mwolski/mynfs 196.17.227.221/255.255.255.0
it means it work. However, there can be little problem caused by firewall. I had to enable all connection to port 2041, to allow external users to connect to my share. To chack if you can mount this share from other computer, just run showmount -e IP_OF_NFS_server.
To run NFS server it is enought.
Later I will descripe how to mount nfs share and also I try to figure out all those nfs options, you can put to /etc/exports.