Thursday, July 29, 2010

AutoCAD 2009 TIF output poor quality ! Problem solved!

I was drawing a system sketch for one of my journal article in AutoCAD 2009 and was trying to export it to .TIF file because it is required by the journal. However, the .TIF file I got by using TIFOUT command in AutoCAD 2009 was really of low quality-the image is blurry, and the text can not be seen in Windows Picture and Fax Viewer (but can be seen in Adobe Photoshop and Microsoft picture manager, which is very weird).

So I tried many many ways, including use other command, such as PNGOUT, JPGOUT, to make other type of image and tried to convert them into .TIF. But I failed.

Now the reason of the problem is clear: AutoCAD has a crappy driver for .TIF output. And here's the solution: install the free PDFCREATOR! This free software is so handy, that I can set the output file type, size, and resolution. It is not only a PDF creator, but can used to print all kinds of other types.

I loev PDFCREATOR!

Monday, May 3, 2010

A computer experiment on statistics: confidence interval for mean and variances of normal population

I am reading Statistics for Science and Engineering by Kinney today.In this book, there is a computer experiment assignment like this:

Select 1000 samples, each of size 10, from a N(10,5) distribution. Calculated the mean for each and a 95% confidence interval for u for each sample. Count the number of these confidence intervals that actually contain the true mean, 10.

I used MATLAB to do this.

clc;
clear all;
close all;
% Generate a normally distributed population.
Po=normrnd(10,5,[1,100000]);
SampleSize=10;
SampleNumber=10000;
%plot Po and histogram Po
figure
plot(Po);
figure
hist(Po, 100);

%take samples, each of size 'SampleSize'
Sa=[];
for i=1:SampleNumber
    for j=1:SampleSize
        index=round(abs(randn(1)*(length(Po)/10-1)))+1;
        Sa(i,j)=Po(index);
    end
end

%calculate the 95% confidence interval of each sample
mean=[];
interval=[];
for i=1:SampleNumber
    mean(i)=sum(Sa(i,:))/SampleSize;
    interval(i,1)=mean(i)-(1.96*5/sqrt(SampleSize));
    interval(i,2)=mean(i)+(1.96*5/sqrt(SampleSize));
end

%count the samples that contain 10
count=0;
for i=1:SampleNumber
    if interval(i,1)>=10 || interval(i,2)<=10
        count=count+1;
    end
end
count/SampleNumber

The results are around 0.05, which means that those confidence intervals have 5% chance not containing the true mean, 10. That's why those are 95% confidence intervals.


Plot of the population:
Histogram of the population:

Thursday, April 29, 2010

Display message in Command Window, not using a pop-up message box

I like to use the input function very much. And I also like to give some instruction to other people who use my code, on what to input, in the command window, but not in a pop-up message box. After a little googling, I found the disp function.

clc;
clear all;
tic;
disp ('Hello, World!');
h=waitbar(0,'Please wait..');
n=0;
for i=1:100
    waitbar(i/100)
    for j=1:100
        for k=0:100;
            n=factorial(2);
        end
    end
end
close(h)
toc

MATLAB progress bar, show the progress of computing

Sometimes during a lengthy procedure, we don't have good way to determine if the code is still running or the computer got stuck. Using a progress bar will let you know approximately how long you have to wait til the run is over. Very cool!

clc;
clear all;
tic;
disp ('Hello, World!');
h=waitbar(0,'Please wait..');
n=0;
for i=1:100
    waitbar(i/100)
    for j=1:100
        for k=0:100;
            n=factorial(2);
        end
    end
end
close(h)
toc

Wednesday, April 28, 2010

xlswrite: output data to excel file {MATLAB functions}

Sometime when a column or a row of data is too long, you can't copy it from MATLAB and then paste directly into an Excel file. A much simpler way to do this is to use the xlswrite function. Just add a line at the end of your code:

xlswrite ('FileName.xls', VariableName)

If you want to put the data into sheet2 in the file, one more input argument is needed:

xlswrite ('FileName.xls', VariableName, 2)

Pretty easy, right?

Sunday, April 11, 2010

Set labels as you want

Let's plot something first.



t=-pi:pi/100:pi;
x=sin(t);
plot(t,x)


And here is what the plot looks like:
Then I want to set the range of x labels from -4 to 12.
xlim([-4 12])
Then I want to show the positive labels only.
set(gca,'xtick',0:1:12)

Then I want to show something different.
set(gca,'xticklabel',{'Jan', 'Feb','Mar', 'and','what', 'ever','you', 'want', 'it', 'to', 'be','!','!@#$@#$'})


Done!

Tuesday, March 16, 2010

Break/Stop a running matlab process: Ctrl + C

I used this to break a dead-end loop long time ago and then forgot about it. It's good a trick to remember.

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...