![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/186524/image.bmp)
Plotting different colored marker points for 4 seperate data entries
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157276/image.jpeg)
Any advice?
Thanks
1 commentaire
Ali
le 29 Oct 2017
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Marker_Counter=1;
figure6=figure;
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
TPR=Input_Data(i:i+9,7);
FPR=Input_Data(i:i+9,8);
plot(FPR,TPR,strcat('-',Markers{Marker_Counter}));
Marker_Counter=Marker_Counter+1;
hold on
end
plot([0.5 1],[0.5 1],'--');
legend('Minpts = 100','Minpts = 200','Minpts = 300','Minpts = 400','Minpts = 500','Minpts = 600','Minpts = 700','Minpts = 800','Minpts = 900','Minpts = 1000','','Location','SouthEast');
xlabel('FPR or (1-Specificity)','FontSize',12,'FontWeight','bold'); ylabel('TPR or Spensitivity)','FontSize',12,'FontWeight','bold');
title('ROC Space');
close(gcf);
-------------------------------------------- code end
end
--------------------------------------- picture link preview
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/186524/image.bmp)
Réponse acceptée
Kelly Kearney
le 19 Oct 2016
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surrogate Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!