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