create a script that makes a x y graph scatterplot with interconnected points. every time that i run the script i want to add new defined x y points in matlab in matlab

To create a scatter plot with interconnected points in MATLAB you can use the plot function. To add new points every time you run the script, you can define the x and y values as arrays and append the new values to these arrays each time the script is run. Here's an example script:

main.m
% Define initial x and y values
x = [1 2 3 4];
y = [4 2 7 1];

% Append new x and y values
newX = [5 6];
newY = [3 8];
x = [x newX];
y = [y newY];

% Create the plot
plot(x, y, '-o')
183 chars
13 lines

In this example, the initial x and y values are defined using arrays with four elements each. The newX and newY arrays represent two new data points that we want to add to the plot.

We then use the concatenation operator [] to append the newX and newY values to the existing x and y arrays. Finally, we create the plot using the plot function with the '-o' option to specify that we want lines connecting the points and circles at the data points.

You can run this script multiple times to add as many new data points as you want to the plot.

related categories

gistlibby LogSnag