yieldstress = 333.8624; a1 = -0.1039; limitxy = 500; vmc = @(x, y) sqrt(x.^2 - x.y + y.^2) - yieldstress.(1+a1*(-sqrt(3)/3)); xx = linspace(-limitxy, limitxy, 1000); yy = linspace(-limitxy, limitxy, 1000); [X, Y] = ndgrid(xx, yy); [C, h] = contour(X, Y, vmc(X, Y), [1 1]); h.LineWidth = 1; h.EdgeColor = "b"; h.FaceColor = "r";,给绘制的曲线添加标注
时间: 2024-02-26 17:55:40 浏览: 123
可以使用 `text` 函数添加标注,代码如下:
yieldstress = 333.8624;
a1 = -0.1039;
limitxy = 500;
vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2) - yieldstress.*(1+a1*(-sqrt(3)/3));
xx = linspace(-limitxy, limitxy, 1000);
yy = linspace(-limitxy, limitxy, 1000);
[X, Y] = ndgrid(xx, yy);
[C, h] = contour(X, Y, vmc(X, Y), [1 1]);
h.LineWidth = 1;
h.EdgeColor = "b";
h.FaceColor = "r";
% 添加标注
text(0, 0, "VMC = 1", "HorizontalAlignment", "center", "VerticalAlignment", "middle", "FontSize", 12);
相关问题
MATLAB 程序yieldstress = 333.8624; %% Drucker-Prager parameter a1 = -0.1039; %% 坐标轴范围 limitxy = 500; %% vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2)-yieldstress.*(1+a1*(-sqrt(3)/3)); % trc = @(x, y) 0.5 * max(cat(3, abs(x - y), abs(x), abs(y))-1, [], 3); xx = linspace(-limitxy, limitxy, 1000); yy = linspace(-limitxy, limitxy, 1000); [X, Y] = ndgrid(xx, yy); [C,h] = contour(X, Y, vmc(X, Y), [1 1]); % xlim([-limitxy, limitxy]); % ylim([-limitxy, limitxy]); w = h.LineWidth; h.LineWidth = 1; % h.LineStyle = ":"; h.EdgeColor = "b"; h.FaceColor = "r";,设定yieldstress为矩阵,并将程序简化
抱歉,您的代码中将 yieldstress 定义为标量而非矩阵。以下是将程序简化后的代码:
yieldstress = 333.8624;
a1 = -0.1039;
limitxy = 500;
vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2) - yieldstress.*(1+a1*(-sqrt(3)/3));
xx = linspace(-limitxy, limitxy, 1000);
yy = linspace(-limitxy, limitxy, 1000);
[X, Y] = ndgrid(xx, yy);
[C, h] = contour(X, Y, vmc(X, Y), [1 1]);
h.LineWidth = 1;
h.EdgeColor = "b";
h.FaceColor = "r";
% xlim([-limitxy, limitxy]);
% ylim([-limitxy, limitxy]);
vmc = @(x, y) sqrt(x.^2 - x.y + y.^2)-yieldstress.(1+a1*(-sqrt(3)/3)); % trc = @(x, y) 0.5 * max(cat(3, abs(x - y), abs(x), abs(y))-1, [], 3); xx = linspace(-limitxy, limitxy, 1000); yy = linspace(-limitxy, limitxy, 1000); [X, Y] = ndgrid(xx, yy); [C5,h5] = contour(X, Y, vmc(X, Y), [1 1]);给曲线添加圆点标记,并控制标记点数量
要给曲线添加圆点标记,可以使用MATLAB函数"plot"。以下是添加标记并控制标记点数量的代码示例:
[C5,h5] = contour(X, Y, vmc(X, Y), [1 1]);
idx = find(C5(1,:) == 1); % 找到标记点的位置
xpts = C5(1,idx+1); % 获取标记点的x坐标
ypts = C5(2,idx+1); % 获取标记点的y坐标
plot(xpts, ypts, 'o'); % 添加圆点标记
set(gca, 'DataAspectRatio', [1 1 1]); % 设置坐标轴比例为1:1
xlim([-limitxy limitxy]); ylim([-limitxy limitxy]); % 设置坐标轴范围
xticks(-limitxy:limitxy/2:limitxy); yticks(-limitxy:limitxy/2:limitxy); % 设置坐标轴刻度
axis square; % 设置坐标轴为正方形
box on; % 显示坐标轴边框
grid on; % 显示坐标轴网格
set(gca, 'GridLineStyle', '-', 'XColor', 'k', 'YColor', 'k', 'LineWidth', 0.5); % 设置网格线样式和颜色
阅读全文