In case you insist on plotting within each iteration, the previous code from Solution 2 can be expanded as follows: Create a figure, add an 'empty' plot to it and store its handle. Solution 3: Dynamically update plot while calculating If you want to calculate the values within a for-loop and plot it afterwards: Pre-allocate the needed variable (in this case y), calculate the values within the for-loop and finally plot it with one single command after the calculation. Solution 2: Calculate values within for-loop and plot afterwards ![]() If you want to plot the points itself, use LineSpec-syntax when calling plot like this 1: plot(x,y,'*') ฤก) Other types of points are possible as well, see the above linked documentation. Note that y is a vector as well as x and that y(n) equals to sin(x(n)) for all n. So the following code does probably what you want: x = linspace(0,2*pi,100) In that case no for-loop is needed because you can calculate and plot vectors directly in MATLAB. ![]() I assume you meant to draw a continuous line. ![]() Solution 1: Vectorized calculation and direct plot With plot(x(i),y) you are plotting 100 single points (one in each iteration) and they are not shown by default.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |