read.m
来自「王小平《遗传算法——理论、应用与软件实现》随书光盘」· M 代码 · 共 53 行
M
53 行
function [out,success]=read(filename,old,retries);
%
% function to wait for the next reading to become available
%
% [out]=read(filename,old,retries)
%
% out = returned process vector
% old = previous index of process vector
% filename = name of the transfer file
% success = 1 for OK read
% success = -1 for timeout
% retries = number of attempts to get the data
%
out=[];
success=-1;
%
% Wait until file becomes available
%
cd d:
for i = 1:retries
%
% Wait for 0.25 secs
%
tic;
while toc < 0.1
drawnow;
end
fid=fopen('transfer.dat','r');
drawnow;
%
% Pause for a tad
%
if fid ~= -1
fclose(fid);
tic;
while toc < 0.1
drawnow;
end
load transfer.dat
if sum(transfer) ~= sum(old)
out=transfer;
success=1;
break;
end
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?