Given two arrays a and b how do you implement it to draw a graph with for loop such that the x axis is set of values from a and y axis is the values from b .i.e the graph is the format 'a' vs 'b........​..........​..........​..........​..........​.......'

조회 수: 1 (최근 30일)
for the above pic if B is arbitary (you can put any value) how do you use for loop to generate 2D plot

채택된 답변

VBBV
VBBV 2020년 11월 24일
편집: VBBV 2020년 11월 25일
clear
t = 0:0.1:10;
for i = 1:length(t)
B(i) = 2*t(i);
end
[x y] = find(B == max(B)) % finds the row and col indices where max value of B occurred
figure(1)
plot(t,B)
axis([0 20 -1 30])
tt = 0:0.2:20;
for i = 1:length(tt)
if tt(i) <= t(y) % use the index in time vector as condition
A(i) = 0;
else
A(i) = 2;
end
end
figure(2)
plot(tt,A)
axis([0 25 0 3])

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by