MATLAB中图形创建和数据处理的顺序
Order of graphics creation and data processing in MATLAB
我正在使用可变步长处理大量数据(>>100k 行)。
我想创建图形并在计算处理数据时绘制它们(用于在出现问题时终止 运行 脚本,或者用花哨的进度给 "customers" 留下深刻印象 "animation").
假设我们有 `sourcefile.txt',其中一列正数 X(n) 在第 n 行,并且:
- 有很多行 X(n+1) < X(n),
- X(n+N) > X(n);其中 N 从小 n 的数千到大 n.
的数十
我想到了:
fID=fopen('sourcefile.txt');
figure;axes; % create figure
act='0';threshold=0;N=0;DATA=0;ii=0;
while ischar(act) % loop until end of file.
ii=ii+1;N=0;
while temp<threshold&&ischar(act) % loop until threshold is overflown (next step) or end-of-file is reached.
act=fgetl(fID);
temp=temp+str2double(act);
N=N+1;
end
line('xdata',ii,'ydata',temp/N,'Marker','o') % New point should appear
threshold=threshold+0.5; % Continue with new stopping rule.
end
问题是输入并处理了循环,然后创建了图形。我如何强制 MATLAB 创建图形然后 calculate/update 绘制数据?
在使用 line
画线后尝试插入 drawnow
。这将刷新图形缓冲区并立即更新您的图形。如果您不这样做,您的图形将显示为空白,直到循环结束,然后图形将与您添加到图形中的对象一起出现。
具体说一下我所说的:
fID=fopen('sourcefile.txt');
figure;axes; % create figure
act='0';threshold=0;N=0;DATA=0;ii=0;
while ischar(act) % loop until end of file.
ii=ii+1;N=0;
while temp<threshold&&ischar(act) % loop until threshold is overflown (next step) or end-of-file is reached.
act=fgetl(fID);
temp=temp+str2double(act);
N=N+1;
end
line('xdata',ii,'ydata',temp/N,'Marker','o') % New point should appear
%%%%%%%%%%%%// Change here
drawnow;
threshold=threshold+0.5; % Continue with new stopping rule.
end
因此,一旦你画了一条线,图形应该立即更新自己,因此对于每次迭代,图形应该更新为一个新的 line
对象。
我正在使用可变步长处理大量数据(>>100k 行)。
我想创建图形并在计算处理数据时绘制它们(用于在出现问题时终止 运行 脚本,或者用花哨的进度给 "customers" 留下深刻印象 "animation").
假设我们有 `sourcefile.txt',其中一列正数 X(n) 在第 n 行,并且:
- 有很多行 X(n+1) < X(n),
- X(n+N) > X(n);其中 N 从小 n 的数千到大 n. 的数十
我想到了:
fID=fopen('sourcefile.txt');
figure;axes; % create figure
act='0';threshold=0;N=0;DATA=0;ii=0;
while ischar(act) % loop until end of file.
ii=ii+1;N=0;
while temp<threshold&&ischar(act) % loop until threshold is overflown (next step) or end-of-file is reached.
act=fgetl(fID);
temp=temp+str2double(act);
N=N+1;
end
line('xdata',ii,'ydata',temp/N,'Marker','o') % New point should appear
threshold=threshold+0.5; % Continue with new stopping rule.
end
问题是输入并处理了循环,然后创建了图形。我如何强制 MATLAB 创建图形然后 calculate/update 绘制数据?
在使用 line
画线后尝试插入 drawnow
。这将刷新图形缓冲区并立即更新您的图形。如果您不这样做,您的图形将显示为空白,直到循环结束,然后图形将与您添加到图形中的对象一起出现。
具体说一下我所说的:
fID=fopen('sourcefile.txt');
figure;axes; % create figure
act='0';threshold=0;N=0;DATA=0;ii=0;
while ischar(act) % loop until end of file.
ii=ii+1;N=0;
while temp<threshold&&ischar(act) % loop until threshold is overflown (next step) or end-of-file is reached.
act=fgetl(fID);
temp=temp+str2double(act);
N=N+1;
end
line('xdata',ii,'ydata',temp/N,'Marker','o') % New point should appear
%%%%%%%%%%%%// Change here
drawnow;
threshold=threshold+0.5; % Continue with new stopping rule.
end
因此,一旦你画了一条线,图形应该立即更新自己,因此对于每次迭代,图形应该更新为一个新的 line
对象。