Matlab Programming Style Guidelines
Some important tricks and commands:
print(gcf, ‘-depsc’, ‘fig1MB4.eps’); %–for saving the Figure as an eps image%—-for printing title with a user defined variable, in this case ‘fn’
title(['Composite Diff (Fechner Law) of : ',int2str(fn)],’Color’,'r’)%—-for displaying with one or more user defined variables, in this case ‘hrzntl’ and ‘vrtcl’
disp(['Size of MB is: ',int2str(hrzntl),'x',int2str(vrtcl)])%—–replacing some elements in a matrix with other value
a(a >0.9 & a<1.1) = 3 ;
%to save multiple images with different filenames from a variable 'img'
for i=1:2400
I=img(:,:,:,i);
imwrite(I, sprintf('file%.02d.jpg', i));
end
SELECTING ONLY A SPECIFIC NUMBER OF ROWS FULFILLING A CONDITION
Assume you have the following data matrix:
A =
1 11 22 33
44 13 12 33
1 14 33 44
Now I would like to delete all rows of this matrix which don't accomplish e.g. the following condition.
octave:6> A(:, 4) == 33
ans =
1
1
0
And I'll get the matrix of this form which only selects these rows:
A_new =
1 11 22 33
44 13 12 33
Try:
A = [
1 11 22 33
44 13 12 33
1 14 33 44
];
idx = ( A(:,4)==33 );
A_new = A(idx,:)
Draw curve on each other
DRAWING FIGURE ON EACH OTHER
figure
a= [70.5, 63.05, 74, 75.9;99.31, 97.79, 99.34, 99.42;89.17, 87.02, 88.68, 89.75];';
b=[2.43, 2.45, 0.07, 0.07];
[AX,H1,H2] =plotyy([1:4],a, [1:4],b, 'bar', 'bar');
set(H1) % a
set(H2,'FaceColor','b') % b
get(H2,'Type') %For illustration purpose only.
pH = arrayfun(@(x) allchild(x),H2);
set(pH,'FaceAlpha',0.25);
ylabel(AX(1),'something')
ylabel(AX(2),'other thing')