File Exchange

## Streamcolor

version 1.0 (2.39 KB) by

Draw 2D or 3D color streamlines.

Updated

STREAMCOLOR(X,Y,U,V,STARTX,STARTY,VMAG) or STREAMCOLOR(X,Y,Z,U,V,W,STARTX,STARTY,STARTZ,VMAG) creates streamlines from 2D or 3D vector data U,V,W. The arrays X,Y,Z define the coordinates for U,V,W and must be monotonic and 3D plaid (as if produced by MESHGRID). STARTX, STARTY, and STARTZ define the starting positions of the stream lines. The handles is NOT returned due to color coding information. Vmag is a matrix of values defines at X,Y,Z. It can be the velocity magnitude or any other variable (vorticity, tke, salinity etc...)

### Mohammad Amin Kazemi (view profile)

Very good function. I'm going to use it to prepare one of my 3D plots in my paper.
Thanks.
Amin,

Richard McCulloch

### Richard McCulloch (view profile)

The file works well, but with the suggestions by Mathieu it works great!. Note vmag should be Vmag and vmax should be Vmax so to use Mathieu's suggestion replace lines 65-90 with this:

for k = 1:length(verts);
vv = verts{k};
if ~isempty(vv)
X=vv(:,1); Y=vv(:,2);
Vcol=uint8(floor(interp2(x,y,Vmag,X,Y)/Vmax*size(cmap,1)));
Vcol(Vcol==0)=1;
for j=1:size(cmap,1),
pos = find(Vcol==j);
if(~isempty(pos) & pos(1)==1), pos(1)=[]; end
if ~isempty(pos),
tempx = [X(pos-1) X(pos) NaN(size(pos))]';
tempy = [Y(pos-1) Y(pos) NaN(size(pos))]';
line(tempx(1:end-1),tempy(1:end-1),'color',cmap(j,:),'linewidth',lw);
end
end
end
end

Richard McCulloch

Mathieu

### Mathieu (view profile)

Great function!
I found one bug, since a colorbar of sizze 64 is assumed, Vcol should be defined as:

Vcol=uint8(floor(interp2(x,y,vmag,X,Y)/vmax*size(cmap,1)));

I also managed to speed up the function by looping through the colormap instead of X. This makes the function 100 times faster. In 2d, this gives:

for k = 1:length(verts);
vv = verts{k};
if ~isempty(vv)
X=vv(:,1); Y=vv(:,2);
Vcol=uint8(floor(interp2(x,y,vmag,X,Y)/vmax*size(cmap,1)));
Vcol(Vcol==0)=1;
for j=1:size(cmap,1),
pos = find(Vcol==j);
if(~isempty(pos) & pos(1)==1), pos(1)=[]; end
if ~isempty(pos),
tempx = [X(pos-1) X(pos) NaN(size(pos))]';
tempy = [Y(pos-1) Y(pos) NaN(size(pos))]';
line(tempx(1:end-1),tempy(1:end-1),'color',cmap(j,:),'linewidth',lw);
end
end
end
end

MATLAB 6.5 (R13)