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!

Monday, April 18, 2011

Open Firefox web browser in Matlab Mac

Wanted to open a web browser from Matlab.
This works for Firefox. Similar things should do for chrome... Lets see.


webDIR = '/Applications/Firefox.app/Contents/MacOS/firefox';
system([webDIR, ' www.usefulcodes.blogspot.com'])

OR,
open -a Firefox
Consulting
http://www.google.com/support/forum/p/Chrome/thread?tid=68ef8a58f86e1fe2&hl=en

But not working for chrome.


Getting Started with MATLAB: A Quick Introduction for Scientists and EngineersDigital Image Processing Using MATLAB, 2nd ed. 

Thursday, April 7, 2011

Code Box for Blogger

Thanks to
http://www.tutzone.org/2009/04/professional-code-box-for-bloggers.html
I have new code block for code section

CODE GOES HERE

Making matlab avi Video with ordered file list


Easy way to display the month-year as string.
Which can then be used to prepare a video out of the file list.


video_obj = VideoWriter('rotation2.avi');
video_obj.FrameRate = 1;

open(video_obj)
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 '.fig'];
disp(fn)
Figtitle = strrep(fn,'_','');

set(gca,'FontSize',30);
eval(sprintf('title(''%s'',''FontSize'',[28],''FontWeight'',''bold'')',Figtitle));
pause(0.1)
F = getframe(fig);
writeVideo(video_obj,F);
pause(0.5)
end
close(video_obj);

end

Friday, April 1, 2011

L, One and I in programming scripts


l1I Courier
l1I Tribuchet
l1I Arial
l1I Helvetica

l1I Times

How many times you have stumbled because of these great bad designs of the fonts?
What is your default font for writing codes?
l1I