필터 지우기
필터 지우기

Plotting different colored marker points for 4 seperate data entries

조회 수: 4 (최근 30일)
Cameron Ysidron
Cameron Ysidron 2016년 10월 19일
댓글: Ali 2017년 10월 29일
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
  댓글 수: 1
Ali
Ali 2017년 10월 29일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Kelly Kearney
Kelly Kearney 2016년 10월 19일
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.
  댓글 수: 1
Cameron Ysidron
Cameron Ysidron 2016년 10월 19일
Thank you so much for the prompt response! This worked perfectly. Also thank you for the advice on how to post.
Have a wonderful day

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by