Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Tuesday, December 13, 2011

Set marker edge width in Matlab figures

A couple of days ago, I plotted about twenty figures and was trying to set the markers with thicker edge. This would be very easy if it was in Excel: just change the 'Marker Line Style' in the 'Format data series' tab. However, it was kind difficult to do in Matlab. At least I didn't get a good solution from the google results on that day.

Today I happened to find the solution when I was playing with Matalb just for fun. The fact is that the 'Marker Edge Width' is actually defined by the 'LineWidth', even when the plot does not use a line to connect the markers..

t=[1:5];
plot(t,sin(t), 's', 'Markersize', 20,'LineWidth', 5)  



Saturday, November 19, 2011

calculate average of every 5 cells in Excel

I have some data sampled at a rate of 1 sample per minutes. However, to use them as input for the following calculation, I have to convert them to the 5 minutes average. Simply put, I want to let B1=average(A1:A5), B2=average(A6:A10), B3=average(A11:A15), ... til B10=average(A46:A50).

I tried VBA code in Excel but didn't make it work. Then I tried Matlab-the code works but it's troublesome to copy/paste all the data between Excel and Matlab back and forth. Finally I figured out a simple way to do this in Excel, by using the OFFSET, ROW, and INDIRECT functions.

The formula to put in cell B1 is:

=AVERAGE(OFFSET(INDIRECT("A"&ROW(A1)*5-4),0,0,5,1))


The Row(A1) returns the row number of the cell, which is '1' in this case. So the INDIRECT("A"&ROW(A1)) *5-4, 0,0,5,1) returns the cell A1 to A5. When dragged to cell B2, the INDIRECT("A"&ROW(A2)) *5-4, 0,0,5,1) returns the cell A6 to A10. So I can drag this formula all the way down to B10 to finish this task.

The file looks like this:

Friday, July 1, 2011

Cell array, self-defined function, and save fig

I learned a lot of important things yesterday, after spend 10 hours in front of computer playing with MatLab. Alright, here's the code I came up with.


%Created on 6/30/2011
clear all
clc
sitenumber='01';


SampleLocation=[];
AER=[];
Err=[];




%% Importing data from intermediate file
filename='whatever it is.xlsx';
D1=xlsread(filename, 'A14:C25');
D2=xlsread(filename, 'I14:K25');
D3=xlsread(filename, 'Q14:S25');
D4=xlsread(filename, 'Y14:AA25');
D5=xlsread(filename, 'AG14:AI25');
D6=xlsread(filename, 'AO14:AQ25');
D7=xlsread(filename, 'AW14:AY25');
D8=xlsread(filename, 'BE14:BG25');
D9=xlsread(filename, 'BM14:BO25');
D10=xlsread(filename, 'BU14:BW25');
D11=xlsread(filename, 'CA14:CD25');
D12=xlsread(filename, 'CJ14:CL25');
D13=xlsread(filename, 'CR14:CT25');
D14=xlsread(filename, 'CZ14:DB25');
D15=xlsread(filename, 'DH14:DJ25');
D16=xlsread(filename, 'DP14:DR25');
D17=xlsread(filename, 'DX14:DZ25');
D18=xlsread(filename, 'EF14:EH25');
DCell={D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,...
    D11,D12,D13,D14,D15,D16,D17,D18}; % Put all the arrays into one big cell array so that each time I can take one cell out and use it as the function input. 


% Use each array as function input % This is a self-defined function
for k=1:18
    [AERate Error]=getDecayrate(DCell{k}); %If use DCell (k), the function won't work.
    
    SampleLocation(1,k)=k;
    AER(1,k)=AERate;
    Err(1,k)=Error;
        
    newfilename=strcat('Site_', sitenumber, '_SampleLocation_', num2str(k),'.fig');
    saveas(gcf,newfilename) % This saveas function works pretty good. The .fig file can be edited later in MatLab.
end


 Result=[SampleLocation', AER', Err'];


%The following function calculates the first-order decay rate of the tracer gas, and returns two parameters. 

function [AER Err] = getDecayrate( location)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here


%AER=Data-1;
TimeS=zeros(1, length(location))';
LNC1=zeros(1, length(location))';
LNC2=zeros(1, length(location))';
for i=2 : length(location)
        TimeS(i)=(location(i,1)-location(1,1))*1440/60;
end


for j=2 : length(location)
    LNC1(j)=log(location(j,2)/location(1,2));
    LNC2(j)=log(location(j,3)/location(1,3));
end


slope1=sum(TimeS.*LNC1)/sum(TimeS.^2);
slope2=sum(TimeS.*LNC2)/sum(TimeS.^2);
AER=abs((slope1+slope2)/2);
Err=abs(AER-abs(slope1));
TimeModel=0:0.01:max(TimeS);
LNC1Model=TimeModel.*slope1;
LNC2Model=TimeModel.*slope2;
plot(TimeS, LNC1, 'xr',TimeS, LNC2, 'sb', TimeModel, LNC1Model,'r', TimeModel, LNC2Model, 'b', 'MarkerSize',10, 'LineWidth', 2)
title ('Location')
xlabel('Time (hours)')
ylabel('Ln(C/C0)')
end


Thursday, October 7, 2010

I was using a lot of greek symbols in my Word document, and usually when I need one, I input a English letter, for example, "a", then highlight it and change the font to symbol. That way, I will have a "α" there. However, if someone changed the font of that letter, it won't show up correctly- a blank will be left there instead of the letter you want.

I did some research and found one way to solve this problem: Firstly type in the unicode for the greek letter, then press "Alt+X". The unicode will be turned into a greek letter, and changing the font will not cause any trouble. The greek letter will show up anyway, just look a little different when different font is used.

And here is the reference for the unicode. This is very cool!

0391 Α  GREEK CAPITAL LETTER ALPHA
0392 Β  GREEK CAPITAL LETTER BETA
0393 Γ  GREEK CAPITAL LETTER GAMMA
0394 Δ  GREEK CAPITAL LETTER DELTA
0395 Ε  GREEK CAPITAL LETTER EPSILON
0396 Ζ  GREEK CAPITAL LETTER ZETA
0397 Η  GREEK CAPITAL LETTER ETA
0398 Θ  GREEK CAPITAL LETTER THETA
0399 Ι  GREEK CAPITAL LETTER IOTA
039A Κ  GREEK CAPITAL LETTER KAPPA
039B Λ  GREEK CAPITAL LETTER LAMDA
039C Μ  GREEK CAPITAL LETTER MU
039D Ν  GREEK CAPITAL LETTER NU
039E Ξ  GREEK CAPITAL LETTER XI
039F Ο  GREEK CAPITAL LETTER OMICRON
03A0 Π  GREEK CAPITAL LETTER PI
03A1 Ρ  GREEK CAPITAL LETTER RHO
03A3 Σ  GREEK CAPITAL LETTER SIGMA
03A4 Τ  GREEK CAPITAL LETTER TAU
03A5 Υ  GREEK CAPITAL LETTER UPSILON
03A6 Φ  GREEK CAPITAL LETTER PHI
03A7 Χ  GREEK CAPITAL LETTER CHI
03A8 Ψ  GREEK CAPITAL LETTER PSI
03A9 Ω  GREEK CAPITAL LETTER OMEGA
03AA Ϊ  GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
03AB Ϋ  GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
03B1 α  GREEK SMALL LETTER ALPHA
03B2 β  GREEK SMALL LETTER BETA
03B3 γ  GREEK SMALL LETTER GAMMA
03B4 δ  GREEK SMALL LETTER DELTA
03B5 ε  GREEK SMALL LETTER EPSILON
03B6 ζ  GREEK SMALL LETTER ZETA
03B7 η  GREEK SMALL LETTER ETA
03B8 θ  GREEK SMALL LETTER THETA
03B9 ι  GREEK SMALL LETTER IOTA
03BA κ  GREEK SMALL LETTER KAPPA
03BB λ  GREEK SMALL LETTER LAMDA
03BC μ  GREEK SMALL LETTER MU
03BD ν  GREEK SMALL LETTER NU
03BE ξ  GREEK SMALL LETTER XI
03BF ο  GREEK SMALL LETTER OMICRON
03C0 π  GREEK SMALL LETTER PI
03C1 ρ  GREEK SMALL LETTER RHO
03C2 ς  GREEK SMALL LETTER FINAL SIGMA
03C3 σ  GREEK SMALL LETTER SIGMA
03C4 τ  GREEK SMALL LETTER TAU
03C5 υ  GREEK SMALL LETTER UPSILON
03C6 φ  GREEK SMALL LETTER PHI
03C7 χ  GREEK SMALL LETTER CHI
03C8 ψ  GREEK SMALL LETTER PSI
03C9 ω  GREEK SMALL LETTER OMEGA
03D1 ϑ  GREEK THETA SYMBOL
03D2 ϒ  GREEK UPSILON WITH HOOK SYMBOL
03D5 ϕ  GREEK PHI SYMBOL
03D6 ϖ  GREEK PI SYMBOL
03DC Ϝ   GREEK LETTER DIGAMMA
03F0 ϰ  GREEK KAPPA SYMBOL
03F1 ϱ   GREEK RHO SYMBOL

Monday, August 2, 2010

How to import JPG/JPEG image into AutoCAD 2009?

It's very hard to find the right button on the menu (or navigation panel ?)of AutoCAD 2009. So just type the command:

IMAGEATTACH

That's it!

A GREAT way to reduce the .TIF file size while keep same high quality

Use Microsoft Office Picture Manager to open the original .TIF file, then export, set export size to 100%, DONE!

I had a >70MB .TIF image with 10000*10000 pixel, after applying this method, the image was shrinked to ~3MB. It's still 10000*10000 pixel and the quality is still good. That's amazing!

Sunday, August 1, 2010

Use Sigmaplot to export high quality .TIF/.TIFF file

Sigmaplot is a powerful tool for drawing scientific charts, and it is also powerful at exporting high quality .TIF/.TIFF file, which can be directly submitted to the journal editors. Here's what I found out how to get high quality images from Sigmaplot:

Firstly, scale down the original graph. The default size of charts are relatively big, usually ~100mm*100mm. It's better to scale them down to 30%. Then select the items, and use highest DPI possible (for me, 600DPI). And change the exporting size to about 3 -5 time larger than the chart size. This will give you a large and clear TIF image.

my-alpine and docker-compose.yml

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