Set Size File Text on Matlab

조회 수: 5 (최근 30일)
Bakka
Bakka 2014년 2월 3일
댓글: Bakka 2014년 2월 4일
Hi everyone, I have program that load text file using uigetfile :
[filepesan lokasi] = uigetfile({'*.txt'},'Browse file message');
this is capacity for file if text file is bigger than capacity
kapasitas=get(handles.txt_nkapaembed,'String');
kapa=str2num(kapasitas);
and codes for get text file size is
txtpesan = strcat(lokasi,filepesan);
infofile=dir(txtpesan);
file=infofile.bytes;
set(handles.txt_nukurfile,'String',num2str(file));
if (file >= kapa)
msg=strcat(num2str(kapa),{' bytes only will embed});
msgbox(msg,'warning','warn');
return
end
but in my algorithm program is that when text file is bigger than "kapasitas" size (ex. 100Kb), the text file should be "crop" until length of 100Kb.
how can I do that? need your advice, many thanks
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 2월 3일
You have not shown your code for reading the file.
Bakka
Bakka 2014년 2월 3일
Hi Mr. Walter, I put codes for reading the files, but now it will show if size file less than capacity, here is the code after return
set(handles.txt_lokasipesan, 'String', txtpesan);
bacapesan=textread(txtpesan,'%s','delimiter','\n','bufsize', 3000000);
set(handles.edt_pesanembedd,'String',bacapesan);

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 3일
if (file >= kapa)
maxfilesize = 100*1024;
else
maxfilesize = inf;
end
set(handles.txt_lokasipesan, 'String', txtpesan);
fid = fopen(txtpesan, 'r');
buffer = fread(fid, maxfilesize, '*char');
fclose(fid);
bacapesan = regexp( buffer, '\n', 'split');
set(handles.edt_pesanembedd,'String',bacapesan);
  댓글 수: 10
Walter Roberson
Walter Roberson 2014년 2월 4일
Your existing code,
bacapesan=textread(txtpesan,'%s','delimiter','\n','bufsize', 3000000);
resulted in bacapesan being a cell array of strings, so your code should already be expecting that. How did you handle it before now?
Bakka
Bakka 2014년 2월 4일
Hi Mr. Walter, finally I found the solution. but could you please check my last question about matlab compiler? it works when I run in m file, but not in exe compiler. Please help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by