how to create a line plot with data from excel?

I am trying to create a line plot using data from an excel document. I am a beginner and am unsure how to actually create the plot. I think I successfully imported the data into my workspace.I have attached the excel sheet with the data. This is what I am aiming to recreate:
figure
%first plot
subplot(1,2,1)
plot(10*ones(1,4), randi(50,1,4), '.k')
hold on
plot(20*ones(1,7), randi(50,1,7), '.k')
hold off
set(gca, 'YTick',[1 10:10:50], 'Xtick',[10 20], 'XTickLabel',{'Morning','Final'})
axis([0 30 0 50])
axis square;
ylabel('Odds');
box 'off';
%second plot
subplot(1,2,2)
plot(10*ones(1,4), randi(50,1,4), '.k')
hold on
plot(20*ones(1,7), randi(50,1,7), '.k')
set(gca, 'YTick',[1 10:10:50], 'Xtick',[10 20], 'XTickLabel',{'Morning','Final'})
axis([0 30 0 50])
axis square;
box 'off';
% white background
set(gcf,'color','w');
my apologies for the lengthy question. Really at a loss here and any advice would be greatly appreciated.

댓글 수: 4

KSSV
KSSV 2018년 5월 22일
YOu have to attach the excel sheet.....an image will not help us to help you..
Dear Minka,
What is the rationale behind a "horse" being plotted on the left or on the right?
Best, Sandro
I have edited the question to include the excel sheet. And there is none, they are just separated into two graphs to avoid having too many lines on one.
KSSV
KSSV 2018년 5월 22일
What is the criteria to connect?

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

답변 (1개)

Sandro Lecci
Sandro Lecci 2018년 5월 22일
편집: Sandro Lecci 2018년 5월 22일

0 개 추천

Dear Minka,
I suggest you use the function line instead of plot. I would do something like this, and I let you change the values wherever you need.
% create 15 pairs of random values
morningOdds = rand(15,1)*50;
finalOdds = rand(15,1)*50;
%create the figure
figure('color', 'w');
subplot(1,2,1)
% Plot only the first 7 pairs
% (xdata --> 10, 20 ; ydata --> combining morning and final Odds for the first 7 pairs)
line([10, 20],[morningOdds(1:7),finalOdds(1:7)], 'marker', '.', 'markersize', 15, 'color', 'k')
% set additional axis properties
set(gca, 'xlim', [5, 25], 'ylim', [0, 50], 'xtick', [10, 20],...
'xticklabel', {'Morning', 'Final'}, 'ytick', 0:10:50, 'box', 'off')
ylabel('Odds')
axis square
% add Text labels
text(repmat(22, 1, 7), finalOdds(1:7), {'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg'})
subplot(1,2,1)
% Similar approach
Now it's up to you to change the values as you want, depending on how your variables look like.
Best, Sandro

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 5월 22일

편집:

2018년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by