MATLAB: Plotting different colored marker points for 4 seperate data entries

multipleplotting

Hello, for an assignment I must calculate the reynold's number given multiple different inputs and output a plot of the temperature versus reynolds number for four different fluid velocity inputs. My code is as given
function [] = reynoldsnumber(InitialT, FinalT, Tinc, InitialV, FinalV,Vinc, FluidDensity, PipeDiameter, ActivationE, EntropicFactor)
R= .008314; Ts=InitialT+273.15; Tf=FinalT+273.15; Ti=Tinc; Vs=InitialV; Vf=FinalV; Vi=Vinc; FD=FluidDensity; PD=PipeDiameter; AE=ActivationE; EF=EntropicFactor; T = [Ts:Ti:Tf]; V = [Vs:Vi:Vf]; i=0; while i<=4; for V = Vs:Vi:Vf for T = Ts:Ti:Tf
i = i+1;
Mu = exp((EF+(AE./(R.*T))));
RN = (FD.*V.*PD)./Mu
LineNum(i)= plot (T,RN,'.','MarkerSize',10);
hold all
end
end
end
xlabel('Temperature (K)') ylabel('Reynold''s number') title('Reynold''s Number Versus Temperature for Varying Fluid Velocities') legend('Linenum1', 'Linenum2', 'Linenum3', 'Linenum4', 'Location', 'NorthWest')
end
My problem is that this plots my marker points with the color varying by "column" of data rather than by each curve of points having different colors. I tried using a while loop so that each iteration of my for loop would change but it had the same result. My final plot looks like this.
Any advice?
Thanks

Best Answer

In your code, you're plotting a single point at a time. Matlab's default behavior is to cycle through colors each time plot is called, so each point gets a new color. The fact that Matlab's default color scheme has 7 colors results in the pattern you see (it's not exactly one color per column, but sort of close).
To fix this, the easiest method would be to plot all the points at once. Your equation lends itself to a vectorized solution, no loops necessary. When plotting a matrix, Matlab's default behavior is to use one color per column of data, which is what you want:
[T, V] = ndgrid(Ts:Ti:Tf, Vs:Vi:Vf);
Mu = exp(EF + AE./(R.*T));
RN = FD .* V .* PD./Mu;
plot(T, RN, '.');
Also, in the future, when posting code, it's helpful if you supply a working example (with all the necessary input variables). The above should work assuming all your parameters are scalars.