フィルターのクリア

Plotting multiple columns with their labels (first row) against the second column (time)

25 ビュー (過去 30 日間)
Hello, I'm trying to plot data that I extracted from a simulation which is in an excel file. I have my time variable in the second column and the value of Stress at different locations starting from the third column. The X-axis variable in the plot will be time i.e. 2nd column whereas the rest of the columns will be variables of Y-axis. I need to plot the Stress values at different locations in a single plot against the X-axis. Also, I need to be able to identify the different lines present in the graph. I am able to plot all the columns against the second column but how do I include the labels for each location, use different color and line type settings for each of them? I'm attaching the table (.mat). I've used the following code (borrowed from this website) to get the initial plot. Thanks.
plot(DATASET194.TIMEs(2:204), DATASET194{2:204, 2:end});
xlabel("time")
ylabel("Mises MPa")

採用された回答

jonas
jonas 2018 年 8 月 28 日
編集済み: jonas 2018 年 8 月 28 日
Here's something to start from
% Load
in=load('DATASET194.mat')
c=in.c;
% Remove first and last col
c(:,[1 end])=[];
% Grab names of variables and remove
str=c(1,2:end);
c(1,:)=[];
% Build table
c=cell2mat(c)
T=array2table(c);
% Convert to timetable
T.c1=seconds(T.c1)
TT=table2timetable(T)
% Plot
h=plot(TT.c1,TT.Variables)
legend(h,str,'location','eastoutside')
set(h(end/2:end),'linestyle','--')
Note that all line handles are stored in h. You can change linestyle after plotting.
  2 件のコメント
ankit varma
ankit varma 2018 年 8 月 28 日
Jonas, Really appreciate your help and efforts here! I wouldn't have figured this out even with online help. Thanks again!
jonas
jonas 2018 年 8 月 28 日
Always happy to help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by