24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 508  |  回复: 6
【奖励】 本帖被评价2次,作者fspdlh增加金币 2
当前主题已经存档。
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

fspdlh

金虫 (正式写手)


[资源] 【原创】一个自编的读取文本文件数据的函数

如题,自编了一个函数,自已感觉用起来还是很方便的,如有需要可以下载。
    可以读取整个文件,读取第N行,读取第M行到第N行,读取第M行到倒数第N行,读取第M次(也可以是最后一次、倒数第M次)出现字符串str的行开始(或结束)的数据,等等。
以下是自编的帮助文档。
%Get text from file
%
%Input paraments:
%   fid:        filename or the indicater of the file
%   sea_tag:    find the target text from the beginningning of the text or
%               the current position
%       0:  the beginningning of the file   
%       1:  the current position
%   beg profix: paraments to point out the beginning of the output text
%   end profix: paraments to point out the endding of the output text
%   tag:        target string, a string inclued in the target line
%   mode:       the method to match the target line
%       1:  comletely matched
%       2:  beginning matched including blanks
%       3:  beginning matched ignoring blanks
%       4:  included
%   count:      the Nth of the target line
%   offset:     offset from the target line
%       negative ingeger: Nth line before from the target line
%       zero:   the target line
%       positive integer: Nth line followed from the target line
%
%The number of input paraments:
% 1     y=GetFileText(  fid )
% 2     y=GetFileText(  fid,    offset )
% 3     y=GetFileText(  fid,    sea_tag,    offset )
% 4     y=GetFileText(  fid,    sea_tag,    beg_offset, end_offset  )
% 6     y=GetLineText(  fid,    beg_sea_tag,   
%                       beg_str,beg_mode,   beg_count,  beg_offset  )
% 7     y=GetFileText(  fid,    beg_sea_tag,    beg_offset,
%                       end_str,    end_mode,   end_count,  end_offset  )
% 7     y=GetFileText(  fid,    beg_sea_tag,
%                       beg_str,    beg_mode,   beg_count,  beg_offset,
%                       end_offset  )
% 10    y=GetFileText(  fid,    beg_sea_tag,   
%                       beg_str,    beg_mode,   beg_count,  beg_offset,
%                       end_str,    end_mode,   end_count,  end_offset  )

[ Last edited by sunxiao on 2009-3-8 at 13:11 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

physics206

新虫 (小有名气)


很不错!谢谢楼主分享
7楼2009-04-02 23:47:41
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 7 个回答

fspdlh

金虫 (正式写手)


读取文件的例子

>> type a.txt

01
02
03  01
04
05
06  01
07
08 01
09
10

>> GetFileText('a.txt')

ans =

    '01'
    '02'
    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'
    '09'
    '10'

>> GetFileText('a.txt',4)

ans =

04

>> GetFileText('a.txt',0,4,-2)

ans =

    '04'
    '05'
    '06  01'
    '07'
    '08 01'
    '09'

>> GetFileText('a.txt',0,'01',4,1,0)

ans =

01

>> GetFileText('a.txt',0,'01',4,2,0)

ans =

03  01

>> GetFileText('a.txt',0,'01',4,2,-1)

ans =

02

>> GetFileText('a.txt',0,'01',4,2,1)

ans =

04

>> GetFileText('a.txt',0,'01',4,-1,-2)

ans =

06  01

>> GetFileText('a.txt',0,'01',4,-2,0)

ans =

06  01

>> GetFileText('a.txt',0,'01',4,-2,0,-1)

ans =

    '06  01'
    '07'
    '08 01'
    '09'
    '10'

>> GetFileText('a.txt',0,'01',4,1,0,'01',4,-1,0)

ans =

    '01'
    '02'
    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'

>> GetFileText('a.txt',0,3,'01',4,3,0)

ans =

    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'
2楼2009-03-02 22:43:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

fox-fox

木虫 (知名作家)


下载,试一下
3楼2009-03-03 08:55:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

woshilsh

荣誉版主 (职业作家)


★★★★★ 五星级,优秀推荐

鼓励!呵呵!加油!多发布优秀资源
4楼2009-03-03 09:15:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 266分,一志愿电气工程,本科材料,求材料专业调剂 +7 哇呼哼呼哼 2026-04-02 8/400 2026-04-05 16:11 by Jimmyhyb
[考研] 材料工程302分求调剂 +7 zyx上岸! 2026-04-04 7/350 2026-04-05 13:52 by imissbao
[考研] 346分的生物与医药08600求调剂 +5 常雨阳上岸 2026-04-05 6/300 2026-04-05 13:42 by imissbao
[考研] 308求调剂 +3 maverick^_^ 2026-04-03 3/150 2026-04-05 12:01 by arrow8852
[考研] 0832食品科学与工程学硕282调剂 +6 鱼在水中游a 2026-04-02 9/450 2026-04-05 11:45 by flysky1234
[考研] 085400电子信息319求调剂(接受跨专业调剂) +5 星星不眨眼喽 2026-04-03 6/300 2026-04-04 21:50 by hemengdong
[考研] 一志愿东北大学085901土木专硕345求调剂 +3 zxt11111 2026-04-04 3/150 2026-04-04 14:21 by 土木硕士招生
[考研] 材料调剂 +11 吴棂颖! 2026-04-03 11/550 2026-04-04 09:56 by 小小树2024
[考研] 材料295 +13 小英11 2026-04-03 14/700 2026-04-04 09:02 by 来看流星雨10
[考研] 266求调剂 +8 学员97LZgn 2026-04-03 8/400 2026-04-04 09:02 by 20021109
[考研] 一志愿双非085502,267分,过四级求调剂 +3 再忙也要吃饭啊 2026-04-03 3/150 2026-04-04 05:03 by gswylq
[考研] 343求调剂085601 +6 要努力学习x 2026-03-29 7/350 2026-04-03 19:49 by 百灵童888
[考研] 283求调剂 +3 jiouuu 2026-04-02 4/200 2026-04-02 14:08 by 哒哒哒呱呱呱
[考研] 266求调剂 +4 学员97LZgn 2026-04-02 4/200 2026-04-02 13:03 by yulian1987
[考研] 一志愿北交大材料工程总分358 +3 cs0106 2026-04-02 5/250 2026-04-02 11:37 by olim
[考研] 一志愿346上海大学生物学 +3 上海大学346调剂 2026-04-01 3/150 2026-04-02 08:36 by w虫虫123
[考研] 292求调剂 +17 木虫er12138 2026-04-01 17/850 2026-04-01 21:37 by 七度不信任
[考研] 生物与医药考研调剂 +5 铁憨憨123425 2026-03-31 5/250 2026-04-01 18:01 by syh9288
[考研] 370求调剂 +3 080700调剂 2026-03-30 3/150 2026-03-31 01:09 by A_Zhe
[考研] 福建理工大学材料学院先进合金团队招收考研调剂学生 +3 大华金商都 2026-03-30 4/200 2026-03-31 01:04 by 方英俊602
信息提示
请填处理意见