I see no lines on my graph after I plot them

ax1 = subplot(3,2,1); ax2 = subplot(3,2,2); ax3 = subplot(3,2,3);
ax4 = subplot(3,2,4); ax5 = subplot(3,2,5);
hold(ax1,'on'); hold(ax2,'on'); hold(ax3,'on'); hold(ax4,'on'); hold(ax5,'on');
for j=0:k
temp = zeros(2,1);
%dual variables plot
for m=1:I
plot(ax1,v(1,m))
ylabel(ax1,'Dual variable 1')
xlabel(ax1,'iteration')
plot(ax2,v(2,m))
ylabel(ax2,'Dual variable 2')
xlabel(ax2,'iteration')
temp = temp + A{m}*x(:,m);
end
%plot sum of all c*x and cost violation
plot(ax3,sum(dot(c',x)))
ylabel(ax3,'Cost function')
xlabel(ax3,'iteration')
plot(ax4,temp(1,1))
ylabel(ax4,'Upper Cost violation')
xlabel(ax4,'iteration')
plot(ax5,temp(2,1))
ylabel(ax5,'Lower Cost violation')
xlabel(ax5,'iteration')
show1 = sprintf('iteration %d completed\n',j);
show2 = sprintf('cost violation is %d and %d against %d and %d\n',temp(1,1), temp(2,1), Pmax, Pmin);
show3 = sprintf('cost function value is %d\n',sum(dot(c',x)));
disp(show1)
disp(show2)
disp(show3)
end
end
when this code runs, I see no lines on my graph plot. What am I doing wrong here?

Answers (2)

k is not defined , it’s better you plot after the loop by saving the values in each iteration by using loop iterator as an index or use marker 'ok' to plot it inside the loop.
We can't run your code because there are a ton of variables that you didn't define or supply.
You're only passing one value to plot, so it will assume it's a y value at x of 0. So it will just plot that one point over and over again, with different y values. Since you don't have a LineStyle specifier in your plot, you will get no line.
Try just accumulating all your x and y in your loop
x(j) = .....
y(j) = .....
Then plot the vectors AFTER the loop
plot(x, y, 'b*-', 'LineWidth', 2, 'MarkerSize', 12);
grid on;
The linestyle specifier of b*- means: blue color, marker of *, and solid lines between the markers.

2 Comments

Actually, I didn't give you all the code. After the start of the first for loop (and before the two nested ones) some operatins happen. k is 100 and I is 200. Right before the start of the first for loop, the matrix k changes. I want to plot this change with respect to the iteration.
OK, but my answer remains the same.

Sign in to comment.

Products

Release

R2018b

Asked:

on 14 Dec 2018

Commented:

on 14 Dec 2018

Community Treasure Hunt

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

Start Hunting!