I have on matrix such as A=[ 2.8866 2.5708 2.9381 2.6234 2.7873 2.8535 3.5818 4.1817 3.6535 4.6312 4.2028 4.4109 3.6008 4.4279 3.8003 3.7995 4.3140 4.4061 5.2382 4.5073 4.2002 3.9283 3.1146 3.0891]. A is one matrix 24*1.each element of matrix is value of losses for each hour a day.for example for hour between 0 ,1 losses is 2.8866 for hour between 1 ,2 the losses is 2.5708. how can i plot losses for 24 hours?
thanks

 Accepted Answer

Star Strider
Star Strider on 19 Aug 2019
Try this:
A=[2.8866 2.5708 2.9381 2.6234 2.7873 2.8535 3.5818 4.1817 3.6535 4.6312 4.2028 4.4109 3.6008 4.4279 3.8003 3.7995 4.3140 4.4061 5.2382 4.5073 4.2002 3.9283 3.1146 3.0891];
Hours = 0.5:23.5;
figure
stairs(Hours, A)
axis([0.5 23.5 0 6])
set(gca, 'XTick',Hours, 'XTickLabel',(0:23))
grid
xlabel('Hours')
ylabel('Loss')

15 Comments

abtin irani
abtin irani on 19 Aug 2019
thanks. it is perfect but has one problem. it doesn't cover for hour 24 . it shows until 23.can you help me?
My pleasure.
Try this:
A=[ 2.8866 2.5708 2.9381 2.6234 2.7873 2.8535 3.5818 4.1817 3.6535 4.6312 4.2028 4.4109 3.6008 4.4279 3.8003 3.7995 4.3140 4.4061 5.2382 4.5073 4.2002 3.9283 3.1146 3.0891];
Hours = 0.5:23.5;
figure
stairs(Hours, A)
axis([0.5 23.5 0 6])
xtl = sprintfc('%.0f', linspace(0, 24, 24));
set(gca, 'XTick',Hours, 'XTickLabel',xtl)
grid
xlabel('Hours')
ylabel('Loss')
That should do what you want.
abtin irani
abtin irani on 19 Aug 2019
thanks.but last value that it shows is element of 23 matrix.in reality for hour=24 the losses shoud be the last element of A.
THIS IS my figure.
please help me.
I have no idea what you want.
Try this:
figure
stairs(Hours, A)
axis([0.5 23.5 0 6])
xtl = sprintfc('%.0f', linspace(1, 24, 24));
set(gca, 'XTick',Hours, 'XTickLabel',xtl)
grid
xlabel('Hours')
ylabel('Loss')
abtin irani
abtin irani on 19 Aug 2019
no it doesn't work. is there any other solution?
I have no idea what ‘doesn’t work’ means.
Try this:
figure
stairs([0:24], [A A(end)])
axis([0 24 0 6])
xtl = sprintfc('%.0f', linspace(0, 24, 25));
set(gca, 'XTick',(0:24), 'XTickLabel',xtl)
grid
xlabel('Hours')
ylabel('Loss')
abtin irani
abtin irani on 19 Aug 2019
first and second answer were better . they just didn't have the value of last element of A.now each 1.5 hour changes losses.in reality each hour(1 hour) should change losses.because each element of matrix A is for one hour.the first answer just didn't support for hour 24 .the last element of A wasn't in figure.thanks
abtin irani
abtin irani on 19 Aug 2019
the last answer worked.thanks million
My pleasure.
Slight variation:
A=[ 2.8866 2.5708 2.9381 2.6234 2.7873 2.8535 3.5818 4.1817 3.6535 4.6312 4.2028 4.4109 3.6008 4.4279 3.8003 3.7995 4.3140 4.4061 5.2382 4.5073 4.2002 3.9283 3.1146 3.0891];
Hours = 1:24;
figure
stairs([0:24], [A A(end)])
axis([0 24 0 6])
xtl = sprintfc('%.0f', linspace(0, 24, 25));
set(gca, 'XTick',(0:24), 'XTickLabel',xtl)
grid
xlabel('Hours')
ylabel('Loss')
I am out of ideas.
abtin irani
abtin irani on 19 Aug 2019
excuse me . thanks for your answerS . i have five matrix .how can i have five matrix in one figure. each matrix should be in specific color.for example first element of each matrix is for first hour, second element of each matrix is for second hour, .....
million thanks.
A=[2.8968 2.6018 3.1997 3.0090 2.8787 2.6936 3.0979 3.4445 4.4046 3.7958 4.4402 3.9971 3.6959 3.5970 3.8980 4.3530 5.0837 4.5077 5.1276 4.6911 4.2197 3.2374 3.0090 2.7497];
B=[ 2.8895 2.5986 3.2015 3.0089 2.8786 2.6934 3.0965 3.4430 4.4044 3.7932 4.4384 3.9998 3.6971 3.5978 3.8989 4.3542 5.0832 4.5089 5.1280 4.6913 4.2191 3.2375 3.0102 2.7452];
C=[2.8896 2.6003 3.2002 3.0082 2.8791 2.6932 3.0969 3.4459 4.4058 3.7962 4.4436 4.0002 3.6949 3.5975 3.9018 4.3528 5.0833 4.5078 5.1273 4.6919 4.2195 3.2378 3.0097 2.7485];
D=[ 2.8886 2.5998 3.1993 3.0092 2.8799 2.6936 3.0966 3.4464 4.4055 3.7957 4.4396 3.9976 3.6949 3.5977 3.8992 4.3519 5.0834 4.5085 5.1280 4.6922 4.2198 3.2378 3.0101 2.7482];
E=[ 2.8869 2.5997 3.2001 3.0084 2.8791 2.6932 3.0965 3.4453 4.4059 3.7949 4.4380 4.0000 3.6952 3.5987 3.9014 4.3560 5.0837 4.5086 5.1281 4.6898 4.2194 3.2376 3.0100 2.7479];
As always, my pleasure.
Assuming that my last plot is what you want, this will plot your new vectors with it:
A=[2.8968 2.6018 3.1997 3.0090 2.8787 2.6936 3.0979 3.4445 4.4046 3.7958 4.4402 3.9971 3.6959 3.5970 3.8980 4.3530 5.0837 4.5077 5.1276 4.6911 4.2197 3.2374 3.0090 2.7497];
B=[ 2.8895 2.5986 3.2015 3.0089 2.8786 2.6934 3.0965 3.4430 4.4044 3.7932 4.4384 3.9998 3.6971 3.5978 3.8989 4.3542 5.0832 4.5089 5.1280 4.6913 4.2191 3.2375 3.0102 2.7452];
C=[2.8896 2.6003 3.2002 3.0082 2.8791 2.6932 3.0969 3.4459 4.4058 3.7962 4.4436 4.0002 3.6949 3.5975 3.9018 4.3528 5.0833 4.5078 5.1273 4.6919 4.2195 3.2378 3.0097 2.7485];
D=[ 2.8886 2.5998 3.1993 3.0092 2.8799 2.6936 3.0966 3.4464 4.4055 3.7957 4.4396 3.9976 3.6949 3.5977 3.8992 4.3519 5.0834 4.5085 5.1280 4.6922 4.2198 3.2378 3.0101 2.7482];
E=[ 2.8869 2.5997 3.2001 3.0084 2.8791 2.6932 3.0965 3.4453 4.4059 3.7949 4.4380 4.0000 3.6952 3.5987 3.9014 4.3560 5.0837 4.5086 5.1281 4.6898 4.2194 3.2376 3.0100 2.7479];
Mtx = [A; B; C; D; E];
Hours = 1:24;
figure
hold all
for k = 1:size(Mtx,1)
stairs((0:24), [Mtx(k,:) Mtx(k,end)])
end
hold off
axis([0 24 0 6])
xtl = sprintfc('%.0f', linspace(0, 24, 25));
set(gca, 'XTick',(0:24), 'XTickLabel',xtl)
grid
xlabel('Hours')
ylabel('Loss')
legend('A','B','C','D','E', 'Location','S')
The stairs function apparenlty only wants vectors, so the loop is necessary.
abtin irani
abtin irani on 20 Aug 2019
it is perfect. but it has a problem.beacause the losses of each matrix are near together. the lines overlap.how can i increase accuracy the loss axis.in order to i identify different lines .
thanks man.
The values are too close together to distinguish them. A plot3 plot is an option, however doing a stairs-type plot with it would probably not be much better, and would definitely be a challenge to write.
Try a bar3 plot instead, to separate them spatially:
figure
bh = bar3(Mtx);
for k = 1:length(bh)
bh(k).CData = bh(k).ZData;
bh(k).FaceColor = 'interp';
end
xlim([0.5 24.5])
zlim([floor(min(Mtx(:))) ceil(max(Mtx(:)))])
xtl = sprintfc('%.0f', linspace(0, 24, 25));
set(gca, 'XTick',(0:24), 'XTickLabel',xtl, 'YTick',(1:5), 'YTickLabel',{'A','B','C','D','E'})
grid
xlabel('Hours')
zlabel('Loss')
grid on
Choose whatever colormap you want. This uses the default.
abtin irani
abtin irani on 20 Aug 2019
thanks you very very much sir.
Star Strider
Star Strider on 20 Aug 2019
As always, my pleasure.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!