A simple record of junior Matlab drawing experience and the solution to the problem that the wrong lengths of plot vectors must be the same

Matlab drawing is simple, convenient, beautiful and editable. It is a good tool for drawing experimental data. Here I will briefly record my use,
as well as the problems encountered during use and their solutions. In fact, it is a small problem, but I have not used it enough so I am not familiar with it. The problems encountered are also very common problems. However, when I checked it, I felt that the answers were not very clear and intuitive, so I made a note of it to prevent encountering it in the future.

clear all;close all;clc;
x=0:1:12;
y=[1,2,3,4,5,6,7,8,9,10,11,12,13]
plot(x,y,'--pr','LineWidth',2,'MarkerSize',10,'MarkerEdgeColor','r')
hold on
plot(x,y1,...)
plot(x,y2,...)
set()#设置坐标轴字体及格式

The above is a simple drawing code. When run in matlab, the corresponding curve will be drawn. By connecting hold on to the plot() command, multiple curves can be drawn on one picture. The problems I encountered during this period are as follows:

"""错误使用plot
矢量长度必须相同

出错plot(line xx)"""

Checked some answers. In fact, after solving it, it seems that the answer is indeed clear, but it is not very intuitive.
The main problem lies in the following two lines of code:

x=0:1:12;
y=[1,2,3,4,5,6,7,8,9,10,11,12]

The range of x is from 0 to 12, with 1 as the interval. This actually contains 13 numbers.
Therefore, the number of values ​​​​in y should be consistent with x, which should also be 13. There will be a problem
if y above is 12 numbers. The points composed of the two are not integer pairs, then the following problem will occur.

Insert image description here
At the beginning, I saw that x was 12 numbers from 0 to 12, so y was also 12 numbers at that time, but I kept getting errors. I changed x:

x=0:1:11;
或者
x=1:1:12;

At this point the error is resolved.
Briefly remember the relevant usage:
Insert image description here
Drawing command description:

plot(x,y,'--pr','LineWidth',2,'MarkerSize',10,'MarkerEdgeColor','r')

Among them, x and y are the horizontal and vertical coordinate values, which can be formed into pairs of points corresponding to
'–pr', --indicates that the line type is a dotted line with double dashes, as shown in the figure above, p represents a five-pointed star, that is, the x and y points use a five-pointed star. means, r means the color of the line is red,
'LineWidth' means the line width,
'MarkerSize' means the size of the five-pointed star,
and finally 'MarkerEdgeColor', 'r' means the color of the five-pointed star is red, and the others are the same.

Attached is a drawing reference link: https://blog.csdn.net/y18771025420/article/details/103245614

おすすめ

転載: blog.csdn.net/qq_44442727/article/details/127642780