I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (while you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum) (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (while you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (while you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (whilwhile you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (whil you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (while you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (whil you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+'0';a+0 %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (whil you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+'0'; %returns
[97 98 99]
Or
sum('abc') == 294
I do not remember in what challenge I saw it someone use (please tell us=), but I found this a neat trick:
Usually if you add matrices you have to have the same size, but for one dimensional (1xn and nx1) matrices there is a shortcut (that does not work in Matlab):
z = (1:5)+(6:10)';
produces the same effect as
[x,y]=meshgrid(1:5,6:10);
z = x+y;
Then something that pawel.boczarski already mentioned: In Octave you can (whil you cannot in Matlab) define auxiliary variables within function handles, AND a variable assignment itself has the value of the assignment so you can really shorten code (well this is an useless example but you'll get the trick):
f=@(n)(z=n+1)*z; %returns (n+1)^2
Then another trick (also applicable in Matlab) is abusing strings for storing (hardcoded) numbers (this neat trick is stolen from feersum), you just need something that interprets the string as number, which is as easy as e.g. adding zero:
a = 'abc';
a+0 %returns
[97 98 99]
Or
sum('abc') == 294