File Exchange

image thumbnail

Streamcolor

version 1.0.0.0 (2.39 KB) by Bertrand Dano
Draw 2D or 3D color streamlines.

10 Downloads

Updated 08 May 2009

View License

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...)

Cite As

Bertrand Dano (2021). Streamcolor (https://www.mathworks.com/matlabcentral/fileexchange/24049-streamcolor), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

Kuidi Zhang

Mohammad Gohardoust

Thanks for the useful code which I really needed. Just for future downloads as suggested by Mathieu, for two cases of two and three dimension, replace the following codes in lines 65-90 with:

h = [];
for k = 1:length(verts)
vv = verts{k};
if ~isempty(vv)
if size(vv,2)==3
X=vv(:,1); Y=vv(:,2); Z=vv(:,3);
Vcol=uint8(floor(interp3(x,y,z,Vmag,X,Y,Z)/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))]';
tempz = [Z(pos-1) Z(pos) NaN(size(pos))]';
h = [h ; line(tempx(1:end-1),tempy(1:end-1),tempz(1:end-1),'color',cmap(j,:),'linewidth',lw)];
end
end
else
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))]';
h = [h ; line(tempx(1:end-1),tempy(1:end-1),'color',cmap(j,:),'linewidth',lw)];
end
end
end
end
end

if nargout>0
hout=h;
end

Mohammad Amin Kazemi

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

Richard McCulloch

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

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 Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!