how can i plot ?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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
採用された回答
Star Strider
2019 年 8 月 19 日
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 件のコメント
abtin irani
2019 年 8 月 19 日
thanks. it is perfect but has one problem. it doesn't cover for hour 24 . it shows until 23.can you help me?
Star Strider
2019 年 8 月 19 日
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
2019 年 8 月 19 日
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.
Star Strider
2019 年 8 月 19 日
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
2019 年 8 月 19 日
no it doesn't work. is there any other solution?
Star Strider
2019 年 8 月 19 日
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
2019 年 8 月 19 日
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
2019 年 8 月 19 日
the last answer worked.thanks million
Star Strider
2019 年 8 月 19 日
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
2019 年 8 月 19 日
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];
Star Strider
2019 年 8 月 19 日
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
2019 年 8 月 20 日
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.
Star Strider
2019 年 8 月 20 日
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
abtin irani
2019 年 8 月 20 日
thanks you very very much sir.
Star Strider
2019 年 8 月 20 日
As always, my pleasure.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
