To plot a graph from data generated in a for loop in MATLAB, you can store the data in an array or matrix within the loop, and then use the plot
function to generate the graph.
Here is an example:
main.m305 chars16 lines
In this example, we generate random data in each iteration of the loop and store it in data
. Then, we use plot
to create a graph using the first column of data
as the x-values and the second column as the y-values.
Make sure to replace the calculations inside the loop with your own code, depending on the specific data you want to plot.
Note: By default, plot
connects the data points with lines. If you want to plot only the points, you can use the scatter
function instead of plot
.
main.m30 chars2 lines
This will show the data points as individual markers on the graph.
gistlibby LogSnag