MATLAB: How to plot all ”k” values and VS values in the same graph? if ı do this code, ı have lots of graphs but ı want a one complete graph.

for loopgraphhelp

Best Answer

After the plot() put in
hold on
Note: this will not be of much use to you unless one of the values involved is a vector, in which case it would draw a series of vertical lines. What you probably need is
kvals = 0:10:km;
numk = length(kvals);
VS = zeros(1, numk);
for kidx = 1 : numk
k = kvals(kidx);
IS=IR;
V(kidx) = Z*k*IR+VR;
end
plot(kvals, V)
Please check the assignment to V that I used. I noticed that you never use k in your code, so the code appears to calculate the same thing for every iteration, so I speculated that you want to use k instead of km for the calculation.