Monday, October 14, 2013

Thursday, September 19, 2013

windrose plot by sigmaplot and matlab

I used two methods to plot wind direction and speed data: Sigmaplot and Matlab.
To correctly show the wind is blowing from the degree, say 10 degree, I need to check the 'clock wise' option. Otherwise the direction will be wrong.
When I used the wind_rose.m, which is downloaded from this link:
http://www.mathworks.com/matlabcentral/fileexchange/17748-windrose
the correct way is to use D-180, and set the 'dtype' to 'meteo'.

This way the two plots made by two different methods will be consistent and correct.

Wednesday, August 14, 2013

Matlab: plot 3D object defined by function g=f(x,y,z)

Usually a 3D object can be described by function of x,y, and z. For example, a 3D sphere centered at (0,0,0) can be described as:
x^2+y^2+z^2=r^2
where the r s the radius of the sphere.
How to plot this object in matlab? Here's my solution:

close all;
clc;
clear;

[x, y,z]=meshgrid(-3:0.1:3, -3:0.1:3,-3:0.1:3);
v1=x.^2+y.^2+z.^2; % create the 1st object
r1=2;% set radius
p1=patch(isosurface(x,y,z,v1,r1));
set(p1, 'FaceColor','r')
hold on

v2=(x-1).^2+(y-1).^2+(z-1).^2;% create the 2nd object
r2=3;
p2=patch(isosurface(x,y,z,v2,r2));
set(p2,'FaceColor','b')
view(3)% set to 3D view 




x^2+y^2+z^2=r^2
 x^2+y^2+z^2=r^2


(x+2-y^2)^2+y^2+z^2=6

(x+2-y^2+z^3)^2+y^2+z^2=6

Wednesday, July 17, 2013

plotting 3D vector field in MATLAB in many different ways

Recently I read post from Dr. Doug Hull's blog:

http://blogs.mathworks.com/videos/2009/10/23/basics-volume-visualization-19-defining-scalar-and-vector-fields/

I liked this video tutorial so much and I really felt that should finish the 'homework' assigned at the very end. So I spent sometime on it and here are my code and figures.

clear;close all;clc;
load wind
speed=sqrt(u.*u+v.*v+w.*w);
%%
figure(1)
scatter3(x(:),y(:),z(:),[],speed(:))
%%
figure(2)
slice(x,y,z,speed,[],[],[5 10 15])
zlim([0 20])
%%
figure(3)
[xs, ys]=meshgrid(60:140, 20:60);
zs=20*ys./xs;
slice(x,y,z,speed,xs,ys,zs)
%%
figure(4)
contourslice(x,y,z,speed,[],[],[5 10 15],20)
zlim([0 20])
view(3)

%%
figure(5)
fv1=isosurface(x,y,z,speed, 10);
fv2=isosurface(x,y,z,speed, 20);
fv3=isosurface(x,y,z,speed, 30);
h1=patch(fv1);
h=patch(fv2);
h3=patch(fv3);
set(h1,'FaceColor',[1, 0.6, 0])
set(h1,'EdgeColor','none')

set(h,'FaceColor',[0, 0.5, 0.5])
set(h,'EdgeColor','none')

set(h3,'FaceColor',[1, 0.4, 1])
set(h3,'EdgeColor','none')
camlight;
lighting gouraud
view(3)

%% 
figure(6)
quiver3(x,y,z,u,v,w);

%%
figure(7)
[cx,cy,cz]=meshgrid([70 80 90 100 110 120], [20 30 40 50 60],[0 5 10 15]);
coneplot(x,y,z,u.*100,v.*100,w.*100,cx,cy,cz,speed);
% set(h, 'edgecolor','none')
shading interp;
view(3)

%%
figure(8)
streamline(x,y,z,u,v,w,80,40,10)
hold on
plot3(80,40,10, 'bo')
view(3)

%%
figure(9)
[sx,sy,sz]=meshgrid(100,[20 30 40], [5 10]);
streamline(x,y,z,u,v,w,sx,sy,sz)
hold on
plot3(sx(:),sy(:),sz(:),'bo')
view(3)

%%
figure(10)
streamslice(x,y,z,u,v,w,[],[],1)
view(3)

%%
figure(11)
streamtube(x,y,z,u,v,w,sx,sy,sz)
shading interp;
view(3)
%%
figure(12)
h=streamribbon(x,y,z,u,v,w,sx,sy,sz);
shading interp;
view(3)


Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12



Thursday, February 28, 2013

Matlab: Remove a cell element from a cell array

Similar to the method to remove unwanted element in a matrix, which is discussed in details in another post (http://matlabnewbie.blogspot.com/2009/07/matlab-remove-all-unwatned-elements-in.html), the unwanted cell element can be removed from a cell array. The only difference is that the strcmp function should be used to identify where all those unwanted cells are.

The following example shows how to remove the cell 'good' from the cell array a, to be somehow humble.

a=[{'this'},{'is'},{'a'},{'good'},{'matlab'},{'blog'}];                 % create a cell array
a=a(~strcmp(a, 'good'))                                                          % remove the 'good' cell

Result looks like this:


a = 

    'this'    'is'    'a'    'matlab'    'blog'

Wednesday, February 27, 2013

Set the properties of a dataset array in Matlab

The percent sign, %, can be used in the matlab code to add explanatory information to the code. Similarly, we can add explanatory information to a dataset array, by using the dataset array properties. The set function can be used to assign values to the dataset property, and the get function can be used to access these information.

DS=dataset(...) % a dataset array is constructed
DS=set(DS, 'Description', 'Whatever can describe the dataset can be put here');
get(DS) % show dataset array properties
summary(DS) % also show dataset array properties 

The 'Description' can be replaced with other properties which are displayed by the get function. 

Friday, February 22, 2013

Convert a dataset to matrix

For the simplest case when the dataset only contains numbers, this double function can be used to convert a dataset to matrix, or a vector if there is only one variable in the dataset:

m=double(ds)

Wednesday, January 9, 2013

Two useful Excel tricks

I was using Excel today and find that I need to do two things. The first one is to automatically alternate row colors (one shaded, one white), so I searched online and found this tutorial very useful.

http://www.techonthenet.com/excel/questions/cond_format2.php


And the other thing I would like to do is to create a list from data validation, so in each cell of one column, I can select the car makers. And I would like to use the next column to record the car model, which mean the second list is dependent on the selection of previous cell's input. I searched online and found that it is called : dependent list for data validation. Here's the tutorial that I followed:

http://www.contextures.com/xlDataVal02.html

Very helpful!

my-alpine and docker-compose.yml

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