在 Matlab 中的同一张图上绘制多条线?情节()或其他什么?
Draw multiple lines on the same graph in Matlab? plot() or something else?
我想画几个点,以及连接一些点的线。所以我这样编程:
prompt = 'Please enter the file name: ';
FileName = input(prompt, 's');
SaturationFile=fopen(FileName);
PoreCount =fscanf(SaturationFile, '%d\n', 1);
ThroatCount=fscanf(SaturationFile, '%d\n', 1);
PI=fscanf(SaturationFile, '%d\n', PoreCount);
PX=fscanf(SaturationFile, '%f\n', PoreCount);
PY=fscanf(SaturationFile, '%f\n', PoreCount);
PS=fscanf(SaturationFile, '%d\n', PoreCount);
TI=fscanf(SaturationFile, '%d\n', ThroatCount);
TB=fscanf(SaturationFile, '%d\n', ThroatCount);
TE=fscanf(SaturationFile, '%d\n', ThroatCount);
TA=fscanf(SaturationFile, '%f\n', ThroatCount);
TL=fscanf(SaturationFile, '%f\n', ThroatCount);
TS=fscanf(SaturationFile, '%d\n', ThroatCount);
TB=TB+1;
TE=TE+1;
MaxA=0;
for i=1:ThroatCount
if TA(i)>MaxA
MaxA=TA(i);
end
end
scale=10;
PX =PX *scale;
PY =PY *scale;
TA =TA *scale;
MaxA=MaxA*scale;
for i=1:ThroatCount
if TS(i)==0
c='cyan';
else
c='black';
end
plot([PX(TB(i)) PX(TE(i))], [PY(TB(i)) PY(TE(i))], 'Color', c, 'LineWidth', TA(i));
end
for i=1:PoreCount
if PS(i)==0
c='cyan';
else
c='black';
end
rectangle('Position', [(PX(i)-0.5*MaxA) (PY(i)-0.5*MaxA) MaxA MaxA], 'FaceColor', c, 'EdgeColor', c, 'Curvature', [1 1]);
end
生成的图片是这样的:
难以置信,抱歉,我不能 post 图片,但是如果你 运行 我的程序带有示例数据,你将很容易得到我的图片。
示例输入文件:
9
10
0
1
2
3
4
5
6
7
8
1.16667
1.16667
1.16667
1.5
1.5
1.5
1.83333
1.83333
1.83333
-0.666667
-0.333333
0
-0.666667
-0.333333
0
-0.666667
-0.333333
0
1
1
0
1
1
0
1
1
0
0
1
2
3
4
5
6
7
8
9
0
0
1
1
3
3
4
4
6
7
1
3
2
4
4
6
5
7
7
8
0.0610206
0.0606029
0.0601841
0.0612494
0.0593242
0.0589063
0.0599607
0.0595583
0.0591209
0.0601974
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
1
1
1
1
1
1
1
1
1
1
问题1:
按照定义,点之间应该有10条线,但是为什么只有1条线呢?
问题2:
看起来点被放大了,但线仍然是那条细线,为什么?
谢谢!请帮帮我,卡了好久
您只需在开始绘制之前(在 ThroatCount 循环之前)打开 figure, hold
。
我想画几个点,以及连接一些点的线。所以我这样编程:
prompt = 'Please enter the file name: ';
FileName = input(prompt, 's');
SaturationFile=fopen(FileName);
PoreCount =fscanf(SaturationFile, '%d\n', 1);
ThroatCount=fscanf(SaturationFile, '%d\n', 1);
PI=fscanf(SaturationFile, '%d\n', PoreCount);
PX=fscanf(SaturationFile, '%f\n', PoreCount);
PY=fscanf(SaturationFile, '%f\n', PoreCount);
PS=fscanf(SaturationFile, '%d\n', PoreCount);
TI=fscanf(SaturationFile, '%d\n', ThroatCount);
TB=fscanf(SaturationFile, '%d\n', ThroatCount);
TE=fscanf(SaturationFile, '%d\n', ThroatCount);
TA=fscanf(SaturationFile, '%f\n', ThroatCount);
TL=fscanf(SaturationFile, '%f\n', ThroatCount);
TS=fscanf(SaturationFile, '%d\n', ThroatCount);
TB=TB+1;
TE=TE+1;
MaxA=0;
for i=1:ThroatCount
if TA(i)>MaxA
MaxA=TA(i);
end
end
scale=10;
PX =PX *scale;
PY =PY *scale;
TA =TA *scale;
MaxA=MaxA*scale;
for i=1:ThroatCount
if TS(i)==0
c='cyan';
else
c='black';
end
plot([PX(TB(i)) PX(TE(i))], [PY(TB(i)) PY(TE(i))], 'Color', c, 'LineWidth', TA(i));
end
for i=1:PoreCount
if PS(i)==0
c='cyan';
else
c='black';
end
rectangle('Position', [(PX(i)-0.5*MaxA) (PY(i)-0.5*MaxA) MaxA MaxA], 'FaceColor', c, 'EdgeColor', c, 'Curvature', [1 1]);
end
生成的图片是这样的: 难以置信,抱歉,我不能 post 图片,但是如果你 运行 我的程序带有示例数据,你将很容易得到我的图片。
示例输入文件:
9
10
0
1
2
3
4
5
6
7
8
1.16667
1.16667
1.16667
1.5
1.5
1.5
1.83333
1.83333
1.83333
-0.666667
-0.333333
0
-0.666667
-0.333333
0
-0.666667
-0.333333
0
1
1
0
1
1
0
1
1
0
0
1
2
3
4
5
6
7
8
9
0
0
1
1
3
3
4
4
6
7
1
3
2
4
4
6
5
7
7
8
0.0610206
0.0606029
0.0601841
0.0612494
0.0593242
0.0589063
0.0599607
0.0595583
0.0591209
0.0601974
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
0.333333
1
1
1
1
1
1
1
1
1
1
问题1: 按照定义,点之间应该有10条线,但是为什么只有1条线呢?
问题2: 看起来点被放大了,但线仍然是那条细线,为什么?
谢谢!请帮帮我,卡了好久
您只需在开始绘制之前(在 ThroatCount 循环之前)打开 figure, hold
。