Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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 Matlab字符串操作_Arrays_String_Matlab - Fatal编程技术网

Arrays Matlab字符串操作

Arrays Matlab字符串操作,arrays,string,matlab,Arrays,String,Matlab,我需要matlab的帮助,使用“strtok”在文本文件中找到一个ID,然后读入或处理包含该ID的行的其余部分。我还需要这个函数来查找(最好使用strtok)相同ID的所有出现,并以某种方式对它们进行分组,以便找到平均值。关于示例代码: ID list being input: (This is the KOIName variable) 010447529 010468501 010481335 010529637 010603247......etc. File with data for

我需要matlab的帮助,使用“strtok”在文本文件中找到一个ID,然后读入或处理包含该ID的行的其余部分。我还需要这个函数来查找(最好使用strtok)相同ID的所有出现,并以某种方式对它们进行分组,以便找到平均值。关于示例代码:

ID list being input:
(This is the KOIName variable)
010447529
010468501
010481335
010529637
010603247......etc.

File with data format:
(This is the StarData variable)
ID>>>>Values

002141865 3.867144e-03  742.000000  0.001121  16.155089  6.297494  0.001677

002141865 5.429278e-03  1940.000000  0.000477  16.583748  11.945627  0.001622

002141865 4.360715e-03  1897.000000  0.000667  16.863406  13.438383  0.001460

002141865 3.972467e-03  2127.000000  0.000459  16.103060  21.966853  0.001196

002141865 8.542932e-03  2094.000000  0.000421  17.452007  18.067214  0.002490
不要被我发布的示例误导,第一个数字重复了大约15行,然后ID改变了,这适用于一整套不同的ID,然后它们作为一个整体再次重复,想想[1,2,3],[1,2,3],主要的区别是ID后面的值,我需要在matlab中求平均值

我目前的代码是:

function Avg_Koi

N = evalin('base', 'KOIName');

file_1 = evalin('base', 'StarData');

global result;

for i=1:size(N)
[id, values] = strtok(file_1);
result = result(id);
result = result(values)
end

end

谢谢你的帮助。

你让我们猜了很多,所以我想你想要这样的东西:

load StarData.txt

IDs = { 010447529;
        010468501;
        010481335;
        010529637;
        010603247;
        002141865}

L = numel(IDs);
values = cell(L,1);

% Iteration through all arrays and creating an cell array with matrices for every ID
for ii=1:L;
    ID = IDs{ii};
    ID_first = find(StarData(:,1) == ID,1,'first');
    ID_last = find(StarData(:,1) == ID,1,'last');

    values{ii} = StarData( ID_first:ID_last , 2:end );
end
当您现在访问索引
ii=6
处理
ID=00211865

MatrixOfCertainID6 = values{6};
你会得到:

0.0038671440    742     0.001121    16.155089   6.2974940   0.001677
0.0054292780    1940    0.000477    16.583748   11.945627   0.001622
0.0043607150    1897    0.000667    16.863406   13.438383   0.001460
0.0039724670    2127    0.000459    16.103060   21.966853   0.001196
0.0085429320    2094    0.000421    17.452007   18.067214   0.002490

。。。进一步计算。

什么是“结果”?不能使用同一个词来标识变量和函数。然后用它来表示id和值。嗯?另外,假设evalin在“StarData”上工作(我不确定它会工作),那么file_1就不是char变量,所以不能在它上使用strtok。键入“whos”(不带引号)查看变量。我很难理解您的问题,但我很确定您希望使用“load”,而不是“evalin”。键入“帮助加载”。您不想计算KOIName和StarData中的表达式(因为没有),只想将这些数据加载到可以操作的Matlab变量中。