Set Size File Text on Matlab
5 次查看(过去 30 天)
显示 更早的评论
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
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
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!