Wanted to learn what time the program was finished on the middle of the night or something like that...
Friday, November 27, 2009
Wednesday, November 25, 2009
Matlab script for figure with background color
This is the Matlab script to make a white circle with dark background.
The figure1 creates a figure with dark background as indicated by the color attribute.
patch is a built in function which creates a light patch (which is a circle).
I tried the built in function "whitebg" which did not work except that it created another color background (viz: whitebg('green') gives me green background without solving the problem).
set(subplot(2,2,1),'Color','Red') actually sets the color for the subplot but I could not make it work for single figure.
Listed in Matlab file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/25935
Here is the code:
Note that the point here is not to generate shape, it can be done with conversion into polar co-ordinates (x,y) into (r,theta). My aim was to have different background for figure.
The figure1 creates a figure with dark background as indicated by the color attribute.
patch is a built in function which creates a light patch (which is a circle).
I tried the built in function "whitebg" which did not work except that it created another color background (viz: whitebg('green') gives me green background without solving the problem).
set(subplot(2,2,1),'Color','Red') actually sets the color for the subplot but I could not make it work for single figure.
Listed in Matlab file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/25935
Here is the code:
Note that the point here is not to generate shape, it can be done with conversion into polar co-ordinates (x,y) into (r,theta). My aim was to have different background for figure.
Thursday, November 12, 2009
Edit the Grub boot loader Menu.lst in Ubuntu
Everytime I upgrade the Ubuntu package, I come across the choice of keeping the boot loader. I try to keep the menu.lst updated by accepting the changes.
This has a consequence: The default value on the menu.lst makes computer boot into another version of Ubuntu.
For example if I had XP/Vista OS as Third Option (selection 2) then after changes it would just start whatever is on the third option.
It could be Ubuntu 9.10, kernel 2.6.x.x.-generic
So, I need some way to edit the menu.lst or the boot loader or the grub menu editor.
How do I do it?
start the terminal
type:
save it and restart.
This has a consequence: The default value on the menu.lst makes computer boot into another version of Ubuntu.
For example if I had XP/Vista OS as Third Option (selection 2) then after changes it would just start whatever is on the third option.
It could be Ubuntu 9.10, kernel 2.6.x.x.-generic
So, I need some way to edit the menu.lst or the boot loader or the grub menu editor.
How do I do it?
start the terminal
type:
gksudo gedit /boot/grub/menu.lst
orsudo vi /boot/grub/menu.lst
remove the un-necessary items on the list.save it and restart.
Thursday, October 1, 2009
How to insert javascript codes in blogger
Inserting the javascript code into the blogger template itself is very good idea.
converted to code by using...
http://www.eblogtemplates.com/blogger-ad-code-converter/
- no need to search for extra place to look for uploading code.
- Easy to manage
- fun
- ...
So, in the section do this:
converted to code by using...
http://www.eblogtemplates.com/blogger-ad-code-converter/
Sunday, September 27, 2009
Wednesday, September 23, 2009
Copy File using command/script in Matlab
This one comes handy when you have repetitive work to copy the files to some directory.
I had to conduct different tests with different parameters and hence wanted an automated way to clean up the files after each test. I wanted to have them organized in folder as per attribution.
This is quite stunning to realize that Matlab has unix features such as ls and pwd
while not cp or mv for copying the files. I started by assuming that cp or mv should work. It does not!
After I copy the files, I can:
I had to conduct different tests with different parameters and hence wanted an automated way to clean up the files after each test. I wanted to have them organized in folder as per attribution.
This is quite stunning to realize that Matlab has unix features such as ls and pwd
while not cp or mv for copying the files. I started by assuming that cp or mv should work. It does not!
After I copy the files, I can:
delete('Untitled.m')
%%%%%%%%%%%%%%%%%%%%%%%%%%-------------%%
function clean_up_fig
jj = 'test';
%%
cd G1_OK
mkdir(jj)
copyfile('*.fig',jj)
copyfile('*.tif',jj)
copyfile('*.mat',jj)
delete('*.tif')
delete('*.fig')
cd ..
%%%%%%%%%%%%%%%%%%%%%%%%%%-------------%%
function clean_up_fig
jj = 'test';
%%
cd G1_OK
mkdir(jj)
copyfile('*.fig',jj)
copyfile('*.tif',jj)
copyfile('*.mat',jj)
delete('*.tif')
delete('*.fig')
cd ..
Sunday, September 20, 2009
Get desired elements from the given array in Matlab
A very simple function to collect the items from the array which meets the required condition
Tuesday, August 18, 2009
Get the desired number of samples
I was wondering how to get n number of sample outputs constrained by the situations given.
AB > C^2
accept C
else reject C
however, I need n non zero final samples.
Wrote this one:
It works for me!
AB > C^2
accept C
else reject C
however, I need n non zero final samples.
Wrote this one:
It works for me!
Tuesday, June 16, 2009
do till condition is met "continue" example
This is a nice example.
This takes x until y(j)>50. After the condition is met it simply passes out.
Better explained by:
continue keeps on taking values does not break the chain.
while break breaks it and comes out of the loop
Contrasted over the
lastly;
clear
clc
y = 1:100;
count = 0
for j = 1:length(y)
disp('go')
if y(j)<20||y(j)>50, break, end
count = count+1
x(j)=y(j)
pause
end
this does not even work while continue will keep looking for the situation.
Break just breaks while continue keep working escaping to the next one and checking!
This takes x until y(j)>50. After the condition is met it simply passes out.
Better explained by:
continue keeps on taking values does not break the chain.
while break breaks it and comes out of the loop
Contrasted over the
lastly;
clear
clc
y = 1:100;
count = 0
for j = 1:length(y)
disp('go')
if y(j)<20||y(j)>50, break, end
count = count+1
x(j)=y(j)
pause
end
this does not even work while continue will keep looking for the situation.
Break just breaks while continue keep working escaping to the next one and checking!
Thursday, June 11, 2009
saving .mat file as per the iteration
I wanted to save the mat files as the iteration progressed.
here is the quick solution:
it saves the mat file with number of iteration as the file name: viz: 100.mat, 200.mat etc.
This is handy when you want to compare the results of the intermediate results as you progress the iteration.
here is the quick solution:
it saves the mat file with number of iteration as the file name: viz: 100.mat, 200.mat etc.
This is handy when you want to compare the results of the intermediate results as you progress the iteration.
Friday, March 20, 2009
How to show the highlighted content in the blogger post
I wanted to highlight certain texts in the blogger posts, mostly codes and others and was having difficulties.
I just looked into the source code of one of the blog and realized that this piece of code will work:
So, I can show the highlighted content in the blogger post
I just looked into the source code of one of the blog and realized that this piece of code will work:
So, I can show the highlighted content in the blogger post
Monday, March 16, 2009
Use of figure handle in Matlab
Friday, February 20, 2009
Playing with wav file in Matlab
To do:
READ THE AUDIO FILE
DISPLAY WAVEFORM
COMPUTE AND DISPLAY FREQUENCY DOMAIN AS FIGURE
% tHE VALIDITY YET TO BE TESTED...
clear all;
close all;
clc;
% import a audio
[y,Fs,nbit]=wavread('your_audio.wav');
% extract left channel only
left=y(:,1);
% calculate the time scale
Ts=1/Fs;
[nsamples,c]=size(y);
tscale=0:Ts:(nsamples-1)*Ts;
%plot left and right channel in time domain
plot(tscale,left,'r');
xlabel('Time (sec)');
ylabel('Amplitude');
%compute the FFT with the proper sampling frequency
fmax=Fs;
%how many points the FFT must be computed on?
N=nsamples;
tscale=0:Ts:(N-1)*Ts;
%N=number of FFT points:
% change it and test the different resolution
fscale=linspace(0,fmax/2,floor(N/2));
spectrum=fft(left,N);
%plot the spectrum of the signal using the appropriate
% frequency scale and module of the coefficients
%plot the magnitude
figure(2);
plot(fscale,abs((spectrum(1:length(fscale)))));
xlabel('Frequency Hz')
ylabel('Module')
READ THE AUDIO FILE
DISPLAY WAVEFORM
COMPUTE AND DISPLAY FREQUENCY DOMAIN AS FIGURE
% tHE VALIDITY YET TO BE TESTED...
clear all;
close all;
clc;
% import a audio
[y,Fs,nbit]=wavread('your_audio.wav');
% extract left channel only
left=y(:,1);
% calculate the time scale
Ts=1/Fs;
[nsamples,c]=size(y);
tscale=0:Ts:(nsamples-1)*Ts;
%plot left and right channel in time domain
plot(tscale,left,'r');
xlabel('Time (sec)');
ylabel('Amplitude');
%compute the FFT with the proper sampling frequency
fmax=Fs;
%how many points the FFT must be computed on?
N=nsamples;
tscale=0:Ts:(N-1)*Ts;
%N=number of FFT points:
% change it and test the different resolution
fscale=linspace(0,fmax/2,floor(N/2));
spectrum=fft(left,N);
%plot the spectrum of the signal using the appropriate
% frequency scale and module of the coefficients
%plot the magnitude
figure(2);
plot(fscale,abs((spectrum(1:length(fscale)))));
xlabel('Frequency Hz')
ylabel('Module')
Subscribe to:
Posts (Atom)