필터 지우기
필터 지우기

Plot a matrix and assign properties for each column

조회 수: 3 (최근 30일)
Anh Mai
Anh Mai 2021년 11월 7일
댓글: Anh Mai 2021년 11월 11일
Hi all;
I am trying to find a shorter way to plot a matrix with 3 columns. I dont know how to assign the properties for each line after plotting. Below is the code that I am using, it will plot a graph with 3 different lines for 3 vector columns in the data.txt. However, I want to differentiate them by assign color for each line.
Of course I can plot 3 different graphs and use hold on, hold off to merge them into one graph. I am wondering if there is a way to assign the plot properties without separate and merge them again. Thank you all for your help.
data=importdata('data.txt');
time=1:1:length(data);
plot(time,data);
title('Daily precipitation of 3 different locations');

채택된 답변

KSSV
KSSV 2021년 11월 7일
A = rand(10,3) ;
x = 1:10 ;
plot(x,A)
legend({'1','2','3'})
B = rand(20,3) ;
x = 1:20 ;
plot(x,B(:,1),'r',x,B(:,2),'b',x,B(:,3),'g')
legend({'1','2','3'})
  댓글 수: 1
Anh Mai
Anh Mai 2021년 11월 11일
Omg, thank you very much. It is good to know this.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by