Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 逐行分析包含tweets的.txt文件_String_Matlab_File Io - Fatal编程技术网

String 逐行分析包含tweets的.txt文件

String 逐行分析包含tweets的.txt文件,string,matlab,file-io,String,Matlab,File Io,如何使用多个fgetl操作让Matlab读取我的30行text.txt文件。我不能把所有的行放在一个变量中,因为我需要使用Matlab分析文件中的信息。我需要检查的信息包括文件中有多少行,以及关于每行中有多少特定字母或符号的问题 到目前为止,我已经开始使用此代码 clear all close all clc %% Questions Two % part a fid = fopen('twitter_data.txt'); twitter = fread(fid,inf,'*char')';

如何使用多个fgetl操作让Matlab读取我的30行text.txt文件。我不能把所有的行放在一个变量中,因为我需要使用Matlab分析文件中的信息。我需要检查的信息包括文件中有多少行,以及关于每行中有多少特定字母或符号的问题

到目前为止,我已经开始使用此代码

clear all
close all
clc
%% Questions Two
% part a
fid = fopen('twitter_data.txt');
twitter = fread(fid,inf,'*char')';
fclose(fid);
只是注意到上面的方法不起作用,因为我需要逐行使用它,而不是一列中的所有字符行向量。此外,您还可以使用找到模式


我使用fgetl太多输入参数时出现以下错误。TwitterProject(第7行)中的错误twitter=fgetl(fid,inf,“*char”);很抱歉。。。这就是我复制/粘贴而不是检查所有内容的结果。现在应该可以了。好的,谢谢,现在可以了,但是我仍然对我得到的变量感到困惑。我怎么说,找出我的文件中或某一行上有多少个符号“#”,我得到变量twitter=-1,fid=20,twitter的最后一个值是-1(文件末尾)。但是如果在while循环中检查它,它将有一些值。至于你还想做什么,这确实是个大问题。。。但是我至少会告诉你一种方法来查找字符串中“#”字符的数量。相关:通常,如果需要,你应该编辑原始问题,而不是开始新问题。编辑一个问题会让它回到前面,最终我们会得到一个好的问题/答案,而不是一系列类似的、不太好的问题。
fid = fopen('twitter_data.txt');
twitter = fgetl(fid);
while ischar(twitter)
   %Process twitter here
   fprintf('Line contains %i # symbols',length(strfind(twitter,'#')));

   %get next line
   twitter = fgetl(fid);
end
fclose(fid);