Please help fix the syntax for my plot.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
% 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 Commenti
Risposte (2)
Voss
il 11 Nov 2022
Modificato: Voss
il 11 Nov 2022
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 Commenti
Torsten
il 11 Nov 2022
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
il 11 Nov 2022
Modificato: Torsten
il 11 Nov 2022
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
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!