Passing variables to plot function

조회 수: 4 (최근 30일)
Hari
Hari 2016년 4월 13일
댓글: Muhammad Usman Saleem 2016년 4월 15일
I have the following plot function
plot([2,7],[3,3],'lineWidth', 40);
Instead of [2,7], I want to pass two variables d1 and d2 that has a set of values stored in it. Can someone please help me with that?

답변 (2개)

dpb
dpb 2016년 4월 13일
Well, it would seem pretty straightforward,
plot(d1,d2,'lineWidth', 40);
assuming X, Y values are in d1, d2, respectively, and they're the same length vectors.
See
doc plot % for details on using it
  댓글 수: 2
Hari
Hari 2016년 4월 13일
Thanks a lot! but the Y value is constant. The two values in X are stored as array of values in two variables. If suppose d1 and d2 has arrays of values then, passing them would look like
plot([d1,d2],[3,3],'lineWidth', 40);
I am sure this won't work!
dpb
dpb 2016년 4월 13일
I'm sure I don't understand from the description. What are the sizes of the various variables and what do you actually want plotted?
The general answer is that plot expects an X and Y array of commensurate length; if vectors orientation doesn't matter. You can do whatever manipulations you need with the variables to build the desired X and Y, plot doesn't care how you write the arrays as long as it is valid syntax that could be written to store the result as a variable.

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


Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 4월 13일
편집: Muhammad Usman Saleem 2016년 4월 13일
let see it what you want
>> d1=[1 3 5 6] % create a vector as x for plot
d1 =
1 3 5 6
>> d2=[4 5 0 10] % create a vector as y for plot
d2 =
4 5 0 10
>> plot(d1,d2,'lineWidth', 40);
do not use [] in d1 and d2
here is the output plot,
  댓글 수: 5
Hari
Hari 2016년 4월 15일
편집: Hari 2016년 4월 15일
I am actually done with it now!! This is my code
d1=xlsread('datafile.xlsx','R69:R76');
d2=xlsread('datafile.xlsx','T69:T76');
plot([d1,2],[3,3],'lineWidth', 40,'color',[1 0 0]);
Thanks a lot!
Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 4월 15일
good then please accept answer for reputation.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by