Please help fix the syntax for my plot.

조회 수: 1 (최근 30일)
Karl
Karl 2022년 11월 10일
댓글: Torsten 2022년 11월 11일
% this is a matrix sorting stocks
% first row is month, 2nd is day, 3rd is year, 4th is how much the price opened for that day, 5th is the high for that day, 6th is the low for that day, and 7th is what the price closed on that day.
Example = [ 5 27 2022 820 827 785 820;
5 28 2022 813 824 801 805;
5 29 2022 808 835 804 822;
5 30 2022 809 835 801 812;
5 31 2022 811 834 802 823;
6 1 2022 858 899 854 898;
6 2 2022 894 908 871 881;
6 3 2022 888 897 880 882;
6 4 2022 889 895 858 864;
6 5 2022 877 886 866 885]
plot(Example(:,5),Example(:,6)) %
title('Stock Highs/Lows')
xlabel('Open Days for 2022')
ylabel('High/Loss in Dollars')
xlim([0 10])
[MIN, mL] = min(Example(:,6)); %
[MAX, ML] = max(Example(:,5)); %
ylim([(MIN-100) (MAX+100)]) %
Hello all, I am trying to learn how to plot column 5 and column 6 of this matrix. Any help fixing my code is appreciated! I believe the lines where I marked a % are the areas where my writing is off. Right now I don't see anything from the graph.
  댓글 수: 2
Torsten
Torsten 2022년 11월 11일
I think you want to plot the columns and not the rows of the matrix.
Karl
Karl 2022년 11월 11일
That's right my bad, I went and edited it.

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

답변 (2개)

Voss
Voss 2022년 11월 11일
편집: Voss 2022년 11월 11일
The XData of the line you plot is Example(:,5), which is in the 800-900 range, but then you set the XLim of the axes to [0 10]. That's why nothing shows up - there's no data in that x-range.
Example = [ 5 27 2022 820 827 785 820;
5 28 2022 813 824 801 805;
5 29 2022 808 835 804 822;
5 30 2022 809 835 801 812;
5 31 2022 811 834 802 823;
6 1 2022 858 899 854 898;
6 2 2022 894 908 871 881;
6 3 2022 888 897 880 882;
6 4 2022 889 895 858 864;
6 5 2022 877 886 866 885];
plot(Example(:,5),Example(:,6)) %
title('Stock Highs/Lows')
xlabel('Open Days for 2022')
ylabel('High/Loss in Dollars')
% xlim([0 10])
[MIN, mL] = min(Example(6,:)); %
[MAX, ML] = max(Example(5,:)); %
ylim([(MIN-100) (MAX+100)]) %
Rather than plotting lows (x) vs highs (y), you probably mean to do something along these lines:
plot(Example(:,5));
hold on
plot(Example(:,6));
  댓글 수: 2
Karl
Karl 2022년 11월 11일
I see, how do I make the x axis the length of the how many values are on the column? I tried:
plot(length(Example),Example(:,5))
hold on
plot(length(Example),Example(:,6))
hold off
I'm still not seeing anything.
Torsten
Torsten 2022년 11월 11일
The number of rows of a matrix is
size(Example,1)
Thus
plot(1:size(Example,1),Example(:,5:6))
If you have such basic MATLAB questions, I think you should take an online course here:

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


Torsten
Torsten 2022년 11월 11일
편집: Torsten 2022년 11월 11일
Example = [ 5 27 2022 820 827 785 820;
5 28 2022 813 824 801 805;
5 29 2022 808 835 804 822;
5 30 2022 809 835 801 812;
5 31 2022 811 834 802 823;
6 1 2022 858 899 854 898;
6 2 2022 894 908 871 881;
6 3 2022 888 897 880 882;
6 4 2022 889 895 858 864;
6 5 2022 877 886 866 885];
hold on
plot(1:10,Example(:,5:6))
hold off
title('Stock Highs/Lows')
xlabel('Open Days for 2022')
ylabel('Highs/Lows in Dollar')
xlim([0 10])
[MIN, mL] = min(Example(:,5:6),[],'all'); %
[MAX, ML] = max(Example(:,5:6),[],'all'); %
ylim([(MIN-100) (MAX+100)]) %
grid on

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by