Monday, November 29, 2010

Can't create index output file in texnic center

I was beating my day because the index was not being printed on the report.
Later, after a good number of search(es),  I found that this is interesting feature of MikTex 2.9

The problem was solved by changing %bm to %tm in the MakeIndex option.

Here is what I did:
Go to build > Define Output Profiles (Alt+F7)
Change %bm to %tm in the MakeIndex option.
Probably same thing needs to happen with Bibtex (if problem persists).


Edit:
I am really glad that you are finding it useful. Happy Texing!


Saturday, November 27, 2010

Entropy Plot for a fair coin toss

Entropy Plot for a fair coin toss

(Yes png as pdflatex does not take eps or pdf format.)
...

clear all
close all
p = 0.0:0.0001:1
entropy = -(p.*log2(p))-((1-p).*log2(1-p)); % in bits try logp to see in nats
figure;
h = plot(p,entropy);
axis tight;
mypretty(h,'Probability','Entropy (bits)','Entropy versus probability for a coin toss')
set(gca, 'LooseInset', [0,0,0,0]);
saveas(h, 'entropy_parabola.png')

Friday, November 26, 2010

Getting rid of un-necessary white spaces in matlab figures

Matlab creates a huge white space around the picture when we do "saveas figure".

There is workaround:

 http://tipstrickshowtos.blogspot.com/2010/08/how-to-get-rid-of-white-margin-in.html
OR
set(gca, 'LooseInset', [0,0,0,0]);

Thursday, November 25, 2010

Matlab codes in Latex

Use the package (mcode.sty) from:
http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package
add:
\usepackage[options]{mcode}
in the "header"
follow:
http://my.opera.com/locksley90/blog/2008/02/25/how-to-include-matlab-source-code-in-a-latex-document

Here is what I did:

This creates a box, pushes everything inside the box (ugly though) and forces next item to new page
\lstinputlisting[label=lst:run_main,breaklines=true, caption={\mcode{run_main.m}}]{G:/academy/random-s-circle/jan14-refine/run_main.m}
\clearpage 

Wednesday, November 24, 2010

Playing with saved figure to decorate

playing with the saved figure
uiopen('SSF_5MOG.fig',1)

% uiopen('intensity_compared5MoG.fig',1)
handle = set(gca);
axis([29 71 29 71])
line([29 71], [50 50],'LineWidth',1,'Color','yellow')
line([50 50],[29 71],'LineWidth',1,'Color','yellow')
handle = gcf;
% dummy = mypretty(handle,'Position of the center of the sensor (cm)','Intensity (LEGO Units)',... 'Intensity measurement compared for 5 MoG')
% hh = legend('prediction1','prediction2','prediction3','prediction4','data1','data2','data3','data4',2);
% dummy = set(gca,'LineWidth',2,'MarkerSize',8)

cd 'ssf-figures'
% saveas('')
% filename = 'intensity_compared5MoG'
filename = 'SSF_5MOG_zoomed'

% pause
saveas(handle,filename,'fig')
saveas(handle,filename,'png')
% close
% cd 'ssf-run-home'

Wednesday, October 13, 2010

Creating movie in matlab

Creating movie in matlab is not so fun. I would suggest saving each picture and using gimp to create the gif instead.


% Script file firstmovie.

% Graphs of y = sin(kx) over the interval [0, pi],
% where k = 1, 2, 3, 4, 5.

m = moviein(5);
x = 0:pi/100:pi;
for i=1:5
h1_line = plot(x,sin(i*x));
set(h1_line,'LineWidth',1.5,'Color','m')
grid
title('Sine functions sin(kx), k = 1, 2, 3, 4, 5')
h = get(gca,'Title');
set(h,'FontSize',12)
xlabel('x')
k = num2str(i);
if i > 1
s = strcat('sin(',k,'x)');
else
s = 'sin(x)';
end
ylabel(s)
h = get(gca,'ylabel');
set(h,'FontSize',12)
m(:,i) = getframe;
pause(2)
end
movie(m)
This was taken from
http://www.math.siu.edu/matlab/tutorial2.pdf

Thursday, September 30, 2010

Writing Equations in Blogspot Blogs


I can write equations in blogspot using latex command: $1+x^2$.


The Function \[\frac{sin(x)}{x}\] .

Since I did not include the p tag to it, it was not interpreted.
http://www.codecogs.com/pages/forums/pagegen.php?id=1675

However, If I add the p html-tag, it will appear as:

The Function \[\frac{sin(x)}{x}\] .



One can also type the latex and paste in the blog posts...
http://codecogs.izyba.com/latex/eqneditor.php
Just remember to put
<script type="text/javascript" src="http://latex.codecogs.com/latex.js"></script>

in the post
I am not sure how to change the dark background...

Tuesday, August 24, 2010

Tex on matlab figure axis labels

It is highly desirable to have tex characters into matlab figures. It is not one to one. But works!
The following is very good resource:
http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f0-4741.html


xlabel(Number of Samples (\textit{N}))
??? xlabel(Number of Samples (\textit{N}))
                  |
Error: Unexpected MATLAB expression.

>> xlabel(Number of Samples (textit{N}))
??? xlabel(Number of Samples (textit{N}))
                  |
Error: Unexpected MATLAB expression.

>> xlabel(Number of Samples (N))
??? xlabel(Number of Samples (N))
                  |
Error: Unexpected MATLAB expression.

>> xlabel('Number of Samples (textit{N})')
>> xlabel('Number of Samples (\textit{N})')
Warning: Unable to interpret TeX string
"\textit{N})"
>> xlabel('Number of Samples ('\textit{N},')')
??? Undefined function or variable 'N'.

>> xlabel('Number of Samples ('\textit{'N'},')')
??? Undefined variable "textit" or class
"textit".


>> xlabel('Number of Samples {\it{N}')
Warning: incomplete command in TeX text
string:
'Number of Samples {\it{N}'
>> xlabel('Number of Samples {\itN}')
Worked!

Thursday, April 15, 2010

save figure as per iteration in matlab

I wanted to save the files in jpeg format as I go...
The following helped me to save it in myplot1.jpeg format.



saveas(gcf,['myplot', num2str(iteration)], 'jpeg')
or

print(gcf, '-djpeg',['Entropy_map_',num2str(j)])

Wednesday, April 14, 2010

Sampling within the range

Explore and get me values that I want within the range

close all
clc
clear all
m = 23;
n = 34;
jumpSTEP = 11;
broken = 1;
playX = [-3:0.1:3];
playY = [-3:0.1:3];
reject = 1;
for jj = 1:1000
    notOK = 1;
    while notOK
        m = m + ceil(jumpSTEP*rand);
        n = n + ceil(jumpSTEP*rand);
        m = rem(m,length(playX));
        n = rem(n,length(playY));
        saveM(jj) = m;
        saveN(jj) = n;
        if m<1
            reject = reject+1;
            continue
        end
        if n<1
            reject = reject+1;
            continue
        end
        if m>1
            notOK =0;
        end
        if n>1
            notOK =0;
        end

    end
end
figure
plot([1:1000],saveM, 'or');
hold on
plot([1:1000],saveN, 'ok');
plot([1:1000], 1, [1:1000], length(playX) );
min(saveM)
min(saveN)


Saturday, April 10, 2010

Unix commands inside matlab: cp, mkdir, rm etc

Implementing the unix commands in the matlab is so easy.
I wanted to automate the file organizing process.
A very simple code combined with http://usefulcodes.blogspot.com/2010/03/recursive-action-into-folders.html is going to work great!
unix('mkdir back') % make directory for backup

unix('cp *.m back') % copy to it or may be more would be better
unix('cp  114.mat back') % copy the file to be saved
unix('cp *.jpg back') % copy the figure to be saved
unix('rm *.*') % delete all files :) not directory

Sunday, April 4, 2010

Nested Function inside function

I had never done a nested function inside another.
It helps to avoid the necessity of having more files as m function. Useful when the function is only called by the same file.
However, the main file itself needs to be saved as function instead of script.


function test
home
a = 1;
b = 2;
test1 = istested(a,b)

function answer = istested(a,b)
a = a+1;
answer = isequal(a,b);
return

Wednesday, March 24, 2010

recursive action into folders

I wanted to do mcc to all the files inside the folder... you know automate it.
This one does it!



clear all
clc
% Read directory names
dirLIST = dir

% get number of directories
N = length(dirLIST)

% Loop through the directories
% Skip the first two..
for n = 3:N

 
    thisDIR = dirLIST(n).name;


        cd(thisDIR);
         disp(['Working on ' thisDIR]);
        mcc -m run_me_deAR.m

        pwd

     
 cd('..');


end

Monday, March 22, 2010

automated mcc to list of files (fail!)

this did not work
:(



clear all
clc
% Read directory names
LISTitems = dir;

% get number of directories
N = length(LISTitems);

% Loop through the directories
% Skip the first two..
for n = 3:N

  
   doTHIS= LISTitems(n).name
 
   mcc -m doTHIS % does not work!
    pause
  

end
% cd('..');
% pwd
   

Saturday, March 20, 2010

automated direcotry listing in matlab

Very simple program for listing the file names as I had to monitor the files from many folders for repetitive works.



clear all
clc
% Read directory names
dirLIST = ls;

% get number of directories
N = length(dirLIST)

% Loop through the directories
% Skip the first two..
for n = 3:N

    % Close all open figures
%     close all;
  
    thisDIR = dirLIST(n,:);

    if isempty(strfind(thisDIR,'.'))
        cd(thisDIR);
      
        ls
        pwd
        pause
%         home
      
 cd('..');

    end
end
cd ..
pwd

Thursday, March 18, 2010

Wednesday, March 17, 2010

Upgrading Texnic Center

Upgrading Texnic Center can be tricky.

When I updated it from previous version, I came across problems.
The MikTex was updated from 2.5 to 2.8. And, I ignorantly had uninstalled the 2.5 version.


I realized that changing 2.5 to 2.8 in the output section worked!!



Instead of this:
C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exeI wanted to use the Yap, it is still not working.
C:\Program Files\MiKTeX 2.8\miktex\bin

Automated Code execution in different folders as per iteration and value

I wanted to automate the code execution in different folder as per iteration.
 This works!



perc = 0.05:0.2:1;
for folder = 1:length(perc)
    percent = perc(folder);
    r = sqrt(percent/pi)*4;
  
    switch(folder)
        case 1
            cd 1
           run_me_deAR(r)
            pwd
%             pause
            cd ..
     
        case 2
            cd 2
            run_me_deAR(r)
            pwd
%             pause
            cd ..
% %         case 3
% %             cd 3
% %             run_me_deAR(r)
% %             pwd
% % %             pause
% %             cd ..
% %         case 4
% %             cd 4
% %             run_me_deAR(r)
% %             pwd
% % %             pause
% %             cd ..
% %         case 5
% %             cd 5
% %            run_me_deAR(r)
% %             pwd
% % %             pause
% %             cd ..
% %           
          
          
          
    end
end

Tuesday, March 16, 2010

Check if the data is already in there

I wanted to test if my new coming data was already contained in the set.
This is very easy!



test = rand(1,23);
A = test(5);
B = test-A;
BB = B(B==0);
if length(BB)>0
    disp('has it!!')
else
%%%  
end
%%%%%%%%%
% another attempt
clc
test = ceil(10*rand(1,10));
doit = 1;
jj =1
while doit
    A = ceil(10*rand);
    B = test-A;
    BB = B(B==0);
    if length(BB)>0
       
%         A = ceil(10*rand);
%         B = test-A;
%         BB = B(B==0);
        jj=jj+1;
        disp('test done!!')
       
    else
        doit = 0;
        %%%
    end
end




Monday, March 15, 2010

Load the matfiles as per iteration

I save the mat files as per iteration.
 This is handy just in case your program is killed.
For the post analysis, I wrote the following to load the .mat file/data.
It loads 1.mat...


for i = 1:18
    filename = [num2str(i)];
    load([filename '.mat'])
    disp('loaded')
    % do something useful
end

Sunday, February 28, 2010

Kile on Mac and troubles

One down...



[ViewDVI] finished with exit status 127
???

$ kdvi test.tex
The program 'kdvi' is currently not installed.  You can install it by typing:
                                    
sudo apt-get install kdvi
bash: kdvi: command not found


sudo port -f activate dbus
sudo port install kile
(From https://trac.macports.org/ticket/26862)

Wednesday, January 20, 2010

Matlab Keyboard Compatible with Windows Keyboard

Play with Matlab compatible to Windows keyboard.
Shortcuts not working?
Check with preferences...






Friday, January 8, 2010

Setting Path Straight in Matlab

Setting Correct Path in Matlab can be tricky as your program evolves to have similar folder structures and filenames.
Just learned how to set the path from Shortcut... wanted to share.


The following code helped me to set the path before I start the functions running...



mypath = pwd

mypath =

/home/../../directory-running

>> path(path,mypath)


Having a shortcut shall not hurt!