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.

Friday, February 26, 2010

Some good blog posts

I ran into a blog yesterday, which is a very good source for Matlab fans. And i found some posts are really useful.

This one tells you how to better manage the memory:
http://obasic.net/preallocate-before-you-loop-it-in-matlab

This one shows how to conveniently set up the interface and default settings by using startup file.
http://obasic.net/set-your-customized-startup-file-for-matlab

Though some of them are geeky:
Twitter from Matlab?
http://obasic.net/how-to-twitter-from-matlab
Sending email using Matlab?
http://obasic.net/how-to-send-e-mail-from-matlab

Anyway, very nice job.

Saturday, February 20, 2010

how to calculate payments on a loan using MS Excel?

Excel has lots of useful built-in functions, and PMT is one of them that can calculate payments on a loan for you. Here is a simple example:

If I get a loan of $5000 from a bank, with the annual interest rate of 8%, and I am supposed to pay it off in 3 years, how much should I pay (OR they will ask me to pay) each month?

And here is how to do the calculation:
Input following into any cell of a Excel worksheet:
=PMT(0.08/12, 3*12, 5000)
and press Enter.

The value shown in the cell ($156.68 ) is the money I am going to pay to the bank each month. Here 0.08/12 is used because the 8% is annual rate, so divide it by 12 to get the monthly rate. And in 3 years, there are 3*12 months, which means the number of payment is 36.

Then, what is the total I pay to the bank? As you might have guessed, it is $156.68*36 (=$5640.55). So the bank will earn $640.55 in this deal at the end. Well, that is a lot of money. Now I am thinking about how to own a bank...


P.S: If you didn't buy MS Excel, that's OK! The Google Docs spreadsheet will do the same thing for you! It is right here: docs.google.com


P.S: this has nothing to do with Matlab, but it is still interesting (at least to me) and useful.



my-alpine and docker-compose.yml

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