Wednesday, May 25, 2011

Full Screen Figure matlab

Full Screen Figure/Image.

scrsz = get(0,'ScreenSize');

% Create figure
h = figure('Position',[1 scrsz(4) scrsz(3) scrsz(4)]);


Related to:
http://usefulcodes.blogspot.com/2011/05/saving-big-matlab-figure-with-subplots.html

Monday, May 23, 2011

Saving Big Matlab Figure with Subplots

MATLAB Advanced GUI DevelopmentSaving Big Figure with Subplots can sometimes be tricky as the titles can be messy and the screen resolution might not help.

Here is what fixed my full-screen plot/image without destroying the titles.

fneps=[Figname,'.eps'];
set(gcf,'PaperPositionMode','auto')
print('-depsc2','-r200',fneps);
The format could be eps or png or fig... as preferred.

Friday, May 20, 2011

Making pretty Figures in Matlab

I had a function calling these with gca option.
h = figure;
%plot

set(h,'LineWidth',1.12);
x_label = 'Class';
y_label = 'Range';
fig_title = char(DATAVAR);
% DATAVAR = variables{j}; from the loop and string list created as a cell structure.
% variables = {'Var1', 'Var2'} etc.
fig_title = regexprep(fig_title, '_', ' ');% To remove the underscores

xlabel(x_label, 'FontSize',[16], 'FontWeight' ,'bold');
ylabel(y_label, 'FontSize',[16], 'FontWeight' ,'bold');
newTitle = [fig_title]; % get the title from File Name (fn)
title(newTitle, 'FontSize',[20], 'FontWeight' ,'bold' );
set(gca,'LineWidth',[2.0], 'FontSize',[14],'FontWeight','bold')

Monday, May 16, 2011

Kile on Mac

Somehow the Macports evaporated out of my system.
So, I end up reinstalling the Kile via macports.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
$ sudo port selfupdate

$ port upgrade outdated
Reinstalled KILE:
$ sudo port install kile


I think installing one of the program last week kicked it out... I will need to verify that.

Saturday, May 14, 2011

Date and Time in File Name matlab

Printing Months name as string for data analysis.
This also checks the existence of the file with the extension ".ext"; say dec_09.ext.


months={'jan','feb','mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'};
for iyear=5: 9

year_st = num2str(iyear,'%2.2i');

for i=1:length(months)
fn=[months{i} '_' year_st '.ext'];
if exist(fn, 'file')

disp(fn)
else
continue
end
end
end

Tuesday, May 10, 2011

Two instances of Matlab in Mac

Typing this on the terminal does the trick!!
$ /Applications/MATLAB_R2010b.app/bin/matlab

Running two instances of matlab: Does it slow down the performance?
Will see...

Monday, May 9, 2011

Saving Matlab Figures as EPS

Saving files as eps is slightly troublesome.

One could use various options. However, for my case, there was cropping in saveas option.

% Print to ps file
Figname = 'TestFigure'
fneps=[Figname,'.eps'];
set(gcf,'PaperPositionMode','auto')
print('-depsc2','-r200',fneps);
% print('-dpsc2','-zbuffer','-r200',fneps);
% saveas(gca,Figname,'psc2');

Friday, May 6, 2011

Cleaning my Keyboard

Let me be litttle funny and produce my own garbage.

I would like to clean my keyboard and see what text does that produce. The work is inspired by the infinite monkey theorem and the dust accumulated on my keyboard.
Start cleanup...
---------
jjjjjjjjjjjjjhjhjhjhjhjhjhjhjhhjhjkjkkknnnmnmnmnmnbnbbbvvvvgvgvgvgfgcffcfcfcfcfcfxxxdxdxxxzzszszszszssawawawawqawqqqqQq q 2qwq3w3w3w4ew4e4ererrdrrrrtrftftyyuyuhuhuhuiuiujiijioioioopopoplplplpl[;[;[[;;];];]']']'
'lmn kn bivcygctfxreszeedsxttgvjb ngyff6tr5rdsxzxewa2wq 1QArdcub omn l,'.,'./.mpn-vccxtdxz5eszewa4esz on ],
/ pob uc x
/?///./....// 1 1///?';lmm, 1q 21 1`12q2q23w3w43e4e4e5r5r5r6t6t7t7yy8u8u9iu9i0i0o-o-p=\]\
.m v ctzeqq 1 1 1` 1` 112-009u8764567lmloiuiucxrrseswasasdxgvchbjm , , ./...,;,;;;l[;[;[';\







---------
End of cleanup


Note: When I was blowing the dust on the keyboard, the force was not sufficient to push any keys and those are un noticed in the process. About 40 microgram of dust was collected in due process.

Thursday, May 5, 2011

Accessing variables as string (matlab)

Easy access to the variables via evaluation command


variables = {'a', 'b','c'}
a = 22;
% operations
eval(variables{1})+2
% works

Wednesday, May 4, 2011

Pie chart with label and percentage


Wanted to have a pie chart with class label as well as the percentage.
This does the job.


class = [Count1 Count2 Count3 Count4];

b = (round(class/sum(class)*100))
% explode = [0,0,1]; % well you can explode it
h=pie(class, {['Class 1 (',num2str(b(1)),'%)'],['Class 2 (',num2str(b(2)),'%)'], ['Class 3 (',num2str(b(3)),'%)'],['Class 4 (',num2str(b(4)),'%)']});
% pie(class,{'Class 1 ','Class 2','Class 3 ', 'Class 4 '})
% well try pie3 too

Monday, May 2, 2011

Extract href link item from the html source matlab

Extract href link item from the html source by using matlab.
The result is that the link is saved in a txt file.


%%
% Search for number of string matches per line.
% replace "href" tag by "ctrl H + manual line break".. in doc ..
% makes life easy
home
clc
filename = 'textsrc.txt';
literal = ' <a href="';

fid = fopen(filename, 'rt');
bbase = 'dsave2'
fid_sh = fopen([bbase '.txt'],'w');

y = 0;
jj = 1;
while feof(fid) == 0
tline = fgetl(fid);

matches = findstr(tline, literal);
num = length(matches);
if num > 0
y = y + num;
% fprintf('%s\n',tline);
fprintf(fid_sh, '%s \n', tline);
end
jj = jj+1;
end
fclose(fid);
fclose(fid_sh)
% this file generates the output on the screen which needs to be copied and
% saved as
% dsave2.txt
% Which will be further operated by refinestr.m

MATLAB for Engineers (2nd Edition)MATLAB Primer, Eighth EditionDigital Signal Processing Using MATLAB

Creating HTML files with favorite pages loaded in matlab

I have saved the pages with sublink such as
http://usefulcodes.blogspot.com/2011/03/how-to-block-website-in-macos.html
http://usefulcodes.blogspot.com/search/label/matlab
etc...

The first part of the link (below) is the home page. The file structure is saved as text array so that textread function in Matlab reads the content as the cell structure. The structure can be accessed iteratively by file{j}.




filename = 'dsave1.txt';
j = 1;

file = textread(filename, '%s', 'delimiter', '\n', ...
'whitespace', '');

for j = 1:length(file)
link = ['http://www.urlurl.com/' file{j}]
% end

file_name = [num2str(j) '.htm'];

fid =fopen(file_name,'wb'); %_id=%s will do the job
fprintf(fid, '<html><head><title>1</title></head><body>');

fprintf(fid, '<iframe name="FRAME" src="%s" width="1040" height="700" frameborder="0" scrolling="no"></iframe></body></html>',link);

fclose(fid);

j = j+1;

end

Just open with Chrome. Tada!