필터 지우기
필터 지우기

Problems using Plot function

조회 수: 1 (최근 30일)
SIDDHARTHA SIDDHARTHA
SIDDHARTHA SIDDHARTHA 2023년 6월 5일
댓글: SIDDHARTHA SIDDHARTHA 2023년 6월 5일
Hi,
I am trying to use the plot function, however, there is no line visible on the graph. lets say, I have
A=[1.1,1.2,1.3];
B=[2.1,2.2,2.3];
C=[3.1,3.2,3.3];
What I want is a plot of [1:3:1] on the X axis and values A(1),B(1),C(1) plotted with respect to point 1, A(2),..C(2) with respect to 2 and A(3)..C(3) with respect to point 3 on X axis.
I thought I would first declare a 3X3 zero matrix and subsequently save all the values of A B C in this array, and try to plot it. No matter what I am doing, I am getting a null plot.
A=[1:3];
B=[4:6];
C=[5:3];
for i=1:3
f(i)=A(i)^2;d(i)=5*B(i);v(i)=A(i)+B(i);
plot (i,f(i),d(i),v(i))
hold on
end
can anyone please help? Thanks in advance

채택된 답변

Walter Roberson
Walter Roberson 2023년 6월 5일
You are plotting one point at a time. By default, plot() does not put in any markers, and plot() can only draw lines when there are at least two adjacent finite values.
You should postpone the plot() until after the loop.
Also, 5:3 is the same as 5:1:3 . The first element is greater than the last element and the increment (1) is positive, so the result of 5:3 is empty.
Note also that plot(VALUE1,VALUE2,VALUE3,VALUE4) would be treated more like plot(VALUE1,VALUE2), plot(VALUE3,VALUE4) -- that is, you are asking to plot i against f(i), and to plot d(i) against v(i)
  댓글 수: 1
SIDDHARTHA SIDDHARTHA
SIDDHARTHA SIDDHARTHA 2023년 6월 5일
Thanks Walter. I am new to MATLAB to be honest... Appreciate your help.

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

추가 답변 (1개)

Pramil
Pramil 2023년 6월 5일
If you want to plot all A B C on the same plot you can use hold on like this :
A=[1.1,1.2,1.3];
B=[2.1,2.2,2.3];
C=[3.1,3.2,3.3];
X = 1:3;
xlabel('X');
ylabel('Value');
plot(X,A);
hold on
plot(X,B);
plot(X,C);
hold off
  댓글 수: 1
SIDDHARTHA SIDDHARTHA
SIDDHARTHA SIDDHARTHA 2023년 6월 5일
Hi Pramil
thanks for the help. Lemme see if this suits my needs.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by