Julia - 在目录

时间:2018-04-17 19:29:23

标签: plot julia data-processing

我是朱莉娅的新手,我正在尝试从目录中的数据文件生成图表。每个文件都是一个单独的图。我有以下代码来生成目录中所有txt文件的数组`allfiles'。

for filename in readdir(pwd())
    if endswith(filename, ".txt")
       push!(allfiles,filename)
    end
end

我还有一个函数myFunction来处理文件中的数据。此函数需要文件名。如何将myFunction应用于allfiles中的每个文件名?我尝试了点语法,它返回以下错误。

MethodError: no method matching myFunction(::Array{String,1})

我还尝试了mapmapslicesbroadcast,并将myFunction置于循环中,遍历allfiles的长度(尽管可能不是正确地)。

编辑,添加了mFunction代码。这是一团糟,不能正常工作。我的想法是我有CSV数据文件,在数据集之间的行中有格式信息。数据文件的第3行具有每个文件中的数据集数量nsets,第4行具有数据点的数量,集合1中的npts。我想设置该函数读取数据集的数量,然后读取并绘制每个数据集。

function myFileFunction(file::String)
  for i=1:length(allfiles)

    m=readdlm(allfiles[i],',' )
    m2=readdlm(allfiles[i], ',', skipstart=4)
    nsets = m[3,1]
    for j=1:nsets
    npts[j] = m[4,1]
    npts2[j] = m[4+npts1+3,1];
    npts3[j] = m[4+npts1+npts2+3+3,1];
    start1 = 1;
    end1 = (start1+npts1-1);
    start2 = (end1+4);
    end2 = (start2+npts2-1);
    start3 = (end2+4);
    end3 = (start3+npts3-1);

    x1 = Float64.(m2[start1:end1,1]);
    y1 = Float64.(m2[start1:end1,2]);
    x2 = Float64.(m2[start2:end2,1]);
    y2 = Float64.(m2[start2:end2,2]);
    x3 = Float64.(m2[start3:end3,1]);
    y3 = Float64.(m2[start3:end3,2]);

    plot(x1,y1)
    plot!(x2,y2)
    plot!(x3,y3)

return "Done"

end
end

0 个答案:

没有答案