Plotting missing data in different colour

조회 수: 5 (최근 30일)
jacob Mitch
jacob Mitch 2019년 11월 16일
댓글: Adam Danz 2019년 11월 16일
Im trying to plot prices as dots and my guess price nan values as different coloured dots. If I have.
years=[1;2;3;4;5;6;7;8;9;10];
price1=[1;1;1;2;3;4;5;6;7;10];
price2=[2;2;2;3;4;5;6;7;8;11];
price3=[1.5;1.5;1.5;nan;2;nan;6;7;9;nan]; %Im filling the nan values by taking (price1+price2)/2 I want to plot the final
guessp=zeros(length(years),1); %price3 against years with the values being in different colours So far I have
for i=1:length(years)
if ~isnan(prices3(ii))
guessp(r)=prices2(i); %gets the price3 value if it is not nan
else
guessp(i)=(price1(i)+price2(i))/2; %fills in the nan data but how do I plot years against my new guessp with the filled
%nan values being different colour dots
end
end
plot(years,guessp) %but with my new nan values in different colours

채택된 답변

Adam Danz
Adam Danz 2019년 11월 16일
years=[1;2;3;4;5;6;7;8;9;10];
price1=[1;1;1;2;3;4;5;6;7;10];
price2=[2;2;2;3;4;5;6;7;8;11];
price3=[1.5;1.5;1.5;nan;2;nan;6;7;9;nan];
guessp=zeros(length(years),1);
guessPrices = (price1 + price2) /2; %all guess prices
guessPrices(~isnan(price3)) = NaN; %remove known prices
figure()
plot(years, price3, 'ro', 'DisplayName', 'Price3')
hold on
plot(years, guessPrices, 'bo', 'DisplayName', 'GuessPrices')
legend()
191116 164948-Figure 2.png
  댓글 수: 2
jacob Mitch
jacob Mitch 2019년 11월 16일
thats perfect thank you
Adam Danz
Adam Danz 2019년 11월 16일
Glad I could help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by