您的位置:首页 > 编程语言 > MATLAB

【数学建模集训系列】公交查询系统的matlab实现-公交站点和线路对应矩阵

2011-08-16 23:37 671 查看
%==============================================================
% 功能: 求站点S和路线L矩阵,表示通过S的所有线路
% 日期: 8/9/2011
%==============================================================
clear,clc
fid=fopen('Bus.txt','r');%打开数据
if fid>0 disp('数据文件打开成功!')
else disp('打开失败'),return
end

SLmat1=zeros(3957,520,2);
temp=[];
while ~feof(fid)
%for m=1:2
temp=fgetl(fid);
if temp(1)=='L'
temp_L=str2num(temp(2:4));%当前L的值
end
fgetl(fid);temp=fgetl(fid);
%第三行
if temp(1)=='上'
n=find(temp=='S');
for i=1:length(n)
n_S=str2num(temp(n(i)+1:n(i)+4));
SLmat1(n_S,temp_L,1)=i;
end
elseif temp(1)=='S'||temp(1)=='环'
n=find(temp=='S');
for i=1:length(n)
n_S=str2num(temp(n(i)+1:n(i)+4));
SLmat1(n_S,temp_L,1)=i;
end
for i=length(n):-1:1
n_S=str2num(temp(n(i)+1:n(i)+4));
SLmat1(n_S,temp_L,2)=length(n)-i+1;
end
end
%第四行
temp=fgetl(fid);
if ~isempty(temp)&&temp(1)=='下'
n=find(temp=='S');
for i=1:length(n)
n_S=str2num(temp(n(i)+1:n(i)+4));
SLmat1(n_S,temp_L,2)=i;
end
end
end

fclose(fid);
%-------------将SL矩阵写入文本文件-------------
save D:\matlab_files\SLdata_sl SLmat1
disp('站点S间的线路矩阵已经保存为D:\matlab_files\SLdata_sl.mat')


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matlab