24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 506  |  回复: 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的回帖

fox-fox

木虫 (知名作家)


下载,试一下
3楼2009-03-03 08:55:18
已阅   回复此楼   关注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的回帖

woshilsh

荣誉版主 (职业作家)


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

鼓励!呵呵!加油!多发布优秀资源
4楼2009-03-03 09:15:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

physics206

新虫 (小有名气)


很不错!谢谢楼主分享
7楼2009-04-02 23:47:41
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 081700学硕,323分,一志愿中国海洋大学求调剂学校 +15 披星河 2026-04-04 15/750 2026-04-05 11:19 by a8144223
[考研] 271分求调剂学校 +12 zph158488! 2026-04-02 13/650 2026-04-05 10:13 by lqwchd
[考研] 生物学303求调剂,一志愿华中农微生物,六级已过,有科研有文章,党员 +4 .fairy.. 2026-03-29 5/250 2026-04-05 10:04 by zhuwenxu
[考研] 调剂 +8 熊二想上岸 2026-04-04 8/400 2026-04-05 05:27 by houyaoxu
[考研] 考研调剂 +6 15615482637 2026-04-04 6/300 2026-04-04 22:43 by yu221
[考研] 可跨专业调剂 +3 周的得地 2026-04-04 6/300 2026-04-04 22:21 by barlinike
[考研] 081200-11408-276学硕求调剂 +3 崔wj 2026-04-04 4/200 2026-04-04 22:12 by 啵啵啵0119
[考研] 301求调剂 +18 骆驼男人 2026-04-02 18/900 2026-04-04 20:33 by 蓝云思雨
[考研] 277工科求调剂 +7 1915668 2026-04-04 7/350 2026-04-04 17:21 by 啊俊!
[考研] 317分 一志愿江南大学 化学工程学硕 求调剂 +6 YinTai 2026-04-03 6/300 2026-04-03 22:30 by 无际的草原
[考研] 303求调剂 +9 DLkz1314. 2026-03-30 9/450 2026-04-03 18:34 by ls刘帅
[考研] 275求调剂 +14 waltzh 2026-04-01 14/700 2026-04-03 11:24 by qqq850810
[考研] 338求调剂,一志愿能源动力,外语是日语203 +5 zzz,,r 2026-04-02 5/250 2026-04-03 09:45 by 蓝云思雨
[考研] 调剂 +3 好好读书。 2026-04-01 6/300 2026-04-02 15:49 by liumengping
[考研] 275学硕081000服从调剂到其他专业,保不住本专业了 +7 一只小小水牛 2026-04-02 8/400 2026-04-02 14:23 by alice-2022
[考研] 314求调剂 +11 1xiaojun23 2026-03-31 12/600 2026-04-02 12:31 by 1xiaojun23
[考研] 298求B区调剂 +4 zzz,,r 2026-04-02 5/250 2026-04-02 12:17 by 土木硕士招生
[考研] 求调剂,一志愿南京师范大学计算机专硕,初试373,六级通过, +3 计算机追梦人 2026-04-01 3/150 2026-04-02 07:57 by fxue1114
[考研] 一志愿北交大材料工程,总分358 +4 cs0106 2026-04-01 4/200 2026-04-02 07:42 by 尚水阁主
[考研] 296求调剂 +10 彼岸t 2026-03-29 10/500 2026-03-30 10:50 by 探123
信息提示
请填处理意见