循环遍历数组的gnuplot [英] loop over array in gnuplot

查看:1990
本文介绍了循环遍历数组的gnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是关系到这个问题:循环结构中的gnuplot?,答案由DarioP(<一个href=\"http://stackoverflow.com/users/2140449/dariop\">http://stackoverflow.com/users/2140449/dariop).

gnuplot的4.6引入了做命令。我怎么可以用它来遍历的例如文件和颜色数组?什么是正确的语法?

 颜色=红,绿,#0000FF
文件=文件1文件2文件3为做[I = 1:3] {
 打印文件(我)。DATLC颜色(I)
}


解决方案

如果你想在一个情节中的所有文件,你需要使用[... 剧情C>(自4.4版本支持)。与循环在几个剧情命令做(仅支持自4.6版本),只能在工作的multiplot 模式。

以下两种溶液都积在一个图中的所有数据,而是在迭代不同位

第一个解决方案使用打印时直接从字符串中提取一个字。

 颜色=红,绿,#0000FF
文件=文件1文件2文件3
积[I = 1:字(文件)。'逸'字(文件,I)LC RGB字(颜色,I)

第二个解决方案直接在单词列表改变了线型,然后遍历,而不是使用索引的。

 颜色=红,绿,#0000FF
文件=文件1文件2文件3
设置为[I = 1:字(颜色)线型我LC RGB字(颜色,I)
积[中文件的文件]文件。'逸'

This question is related to the question "Loop structure inside gnuplot?" and the answer by DarioP (http://stackoverflow.com/users/2140449/dariop).

gnuplot 4.6 introduced the do command. How can I use this to loop over an array of for example files and colors? What is the correct syntax?

colors = "red green #0000FF"
files = "file1 file2 file3"

do for [i=1:3] {
 plot files(i).".dat" lc colors(i)
}

解决方案

If you want to have all files in a single plot, you need to use plot for[... (supported since version 4.4). Looping over several plot commands with do for (supported only since version 4.6) works only in multiplot mode.

The following two solutions both plot all data in one graph, but differ a bit in the iterations.

The first solution uses word to extract a word from a string directly when plotting.

colors = "red green #0000FF"
files = "file1 file2 file3"
plot for [i=1:words(files)] word(files, i).'.dat' lc rgb word(colors, i)

The second solution changes the linetype and then iterates directly over the word list instead of using an index.

colors = "red green #0000FF"
files = "file1 file2 file3"
set for [i=1:words(colors)] linetype i lc rgb word(colors, i)
plot for [file in files] file.'.dat'

这篇关于循环遍历数组的gnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆