Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.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
Arrays 影响存储阵列索引的文件行?_Arrays_Matlab_File_Indexing_Octave - Fatal编程技术网

Arrays 影响存储阵列索引的文件行?

Arrays 影响存储阵列索引的文件行?,arrays,matlab,file,indexing,octave,Arrays,Matlab,File,Indexing,Octave,我有一个简单的八度代码,只需打开3个文件(一次一个)并扫描每行两个字符串中的一个,如果找到匹配的字符串,它将提取字符串后面的数字,并将该数字附加到数组中 clear names = dir('*txt'); rec = []; emit = []; for i = 1:length(names) name = names(i).name; fid = fopen(name); while !(feof(fid)) tline = fgets(fid); if !

我有一个简单的八度代码,只需打开3个文件(一次一个)并扫描每行两个字符串中的一个,如果找到匹配的字符串,它将提取字符串后面的数字,并将该数字附加到数组中

clear

names = dir('*txt');

rec = [];
emit = [];

for i = 1:length(names)
  name = names(i).name;
  fid = fopen(name);
  while !(feof(fid))
    tline = fgets(fid);
    if !(isempty(regexp(tline,'reception: ')))
      offset = regexp(tline,'reception: ');
      val = str2double(strtok(tline(offset+11:end)));
      rec(end+1) = val;
    elseif !(isempty(regexp(tline,'emission: ')))
      offset = regexp(tline,'emission: ');
      val = str2double(strtok(tline(offset+10:end)));
      emit(end+1) = val;
    end
  end
length(rec)
end

fn = strcat(name,'REC.mat');
save('-mat',fn,'rec');
fn = strcat(name,'EMIT.mat');
save('-mat',fn,'emit');
我希望“长度(rec)”是一个累积值,但它不是-它只是打印“接收”的数量:“每个文件中的行数,每次加载一个新文件时,就像清除数组“rec”和“emit”,为什么会发生这种情况?这与文件索引有关吗?这会如何影响数组

我用一个简单的测试程序尝试了这一点,结果完全符合我的预期:

clear

test = [];
fin = 5;

for i = 1:3
  j = 0;
  while (j<fin)
    j = j+1;
    test(end+1) = j;
  end
fin = fin+5;
length(test)
end
在for循环的每次迭代之后:

totalRec = [totalRec,rec]
但我对它发生的原因很感兴趣

编辑:

数据文件内容的示例如下所示:-

2017.07.13 10:31:04:346301 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:168 INFO Control_data_reception: 10936 us
2017.07.13 10:31:04:363889 FESA.USR.ABT_SocketServer.RealTime.RT_NewCycleReady src/ABT_SocketServer/RealTime/RT_NewCycleReady.cpp:52 INFO RT_NewCycleReady execute -> Start
2017.07.13 10:31:05:050910 FESA.USR.ABT_SocketServer.RealTime.RT_ELFTReady src/ABT_SocketServer/RealTime/RT_ELFTReady.cpp:49 INFO RT_ELFTReady execute -> Start
2017.07.13 10:31:05:057764 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:112 INFO acquisition_data_emission: 6469 us
2017.07.13 10:31:05:474323 FESA.USR.ABT_SocketServer.RealTime.RT_endCycle src/ABT_SocketServer/RealTime/RT_endCycle.cpp:49 INFO RT_endCycle execute -> Start
2017.07.13 10:31:05:504081 FESA.USR.ABT_SocketServer.RealTime.RT_NewCycle src/ABT_SocketServer/RealTime/RT_NewCycle.cpp:59 INFO RT_NewCycle execute -> Start
2017.07.13 10:31:05:544370 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:168 INFO Control_data_reception: 9424 us

您在这里的代码工作方式如所述:长度(rec)随着每个文件“receipt:”的出现次数而增长。我看不到任何影响“rec”的“魔力”。测试用例的工作方式如所述,实际代码(从文件中读取)没有。我也看不到任何魔力,但是,例如,对于出现次数为100、200和300的文件接收:“分别打印100、200、300而不是100、300、600…正如我上面所说,我会看到100300600和您的第一个代码部分工作。也许从“dir”中止特殊排序的假设是错误的?然而,如果没有良好的MCVE()很难帮上忙。你能发布你正在使用的文本文件的小样本吗?是的。最好的方法是什么?在问题中?或者添加一个链接?
2017.07.13 10:31:04:346301 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:168 INFO Control_data_reception: 10936 us
2017.07.13 10:31:04:363889 FESA.USR.ABT_SocketServer.RealTime.RT_NewCycleReady src/ABT_SocketServer/RealTime/RT_NewCycleReady.cpp:52 INFO RT_NewCycleReady execute -> Start
2017.07.13 10:31:05:050910 FESA.USR.ABT_SocketServer.RealTime.RT_ELFTReady src/ABT_SocketServer/RealTime/RT_ELFTReady.cpp:49 INFO RT_ELFTReady execute -> Start
2017.07.13 10:31:05:057764 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:112 INFO acquisition_data_emission: 6469 us
2017.07.13 10:31:05:474323 FESA.USR.ABT_SocketServer.RealTime.RT_endCycle src/ABT_SocketServer/RealTime/RT_endCycle.cpp:49 INFO RT_endCycle execute -> Start
2017.07.13 10:31:05:504081 FESA.USR.ABT_SocketServer.RealTime.RT_NewCycle src/ABT_SocketServer/RealTime/RT_NewCycle.cpp:59 INFO RT_NewCycle execute -> Start
2017.07.13 10:31:05:544370 FESA.USR.ABT_SocketServer.RealTime.CustEvtSrcProducer src/ABT_SocketServer/RealTime/CustEvtSrcProducer.cpp:168 INFO Control_data_reception: 9424 us