我正在尝试初始化矩阵(使用Eigen库),以便在创建时具有非零值.没有for循环,有没有一个很好的方法来做到这一点?
例如,如果我想将整个矩阵初始化为1.0,我想做类似的事情:
Eigen::MatrixXd mat(i,j) = 1.0;
Run Code Online (Sandbox Code Playgroud)
要么
Eigen::MatrixXd mat(i,j);
mat += 1.0;
Run Code Online (Sandbox Code Playgroud)
(我习惯于在MATLAB中使用这种类型的东西,它会让Eigen比现在更好用.我怀疑有一个内置的方法可以做到这一点,我还没有找到.)
这个问题的一个子问题是如何将矩阵元素块设置为一个设定值,如下所示:
mat.block(i,j,k,l) = 1.0;
Run Code Online (Sandbox Code Playgroud) 当我使用C++ 11标准(该std::stod函数)的特性编译一个简单的代码时,GCC 4.9.1失败并出现以下错误:
example.cpp: In function 'int main()':
example.cpp:10:18: error: 'stod' is not a member of 'std'
double earth = std::stod (orbits,&sz);
^
example.cpp:11:17: error: 'stod' is not a member of 'std'
double moon = std::stod (orbits.substr(sz));
^
Run Code Online (Sandbox Code Playgroud)
什么?
我使用的命令是g++ -std=c++11 example.cpp.
这是测试代码(在其他系统上编译良好):
// stod example from http://www.cplusplus.com/reference/string/stod/
#include <iostream> // std::cout
#include <string> // std::string, std::stod
int main ()
{
std::string orbits ("365.24 29.53");
std::string::size_type sz; // alias of size_t
double earth = std::stod …Run Code Online (Sandbox Code Playgroud) 我试图在gnuplot中的eps和pdf终端之间获得一些一致的输出.麻烦的是他们似乎不同地理解大小单位; 以英寸为单位的相同指定大小将导致pdf输出的字体大小更大:
set terminal postscript eps enhanced colour size 10in,8in font 'Arial-Bold,14'
set output 'my_eps.eps'
set title 'My plot'
plot sin(x) notitle
set terminal pdfcairo size 10in,8in font 'Arial-Bold,14'
set output 'my_pdf.pdf'
replot
Run Code Online (Sandbox Code Playgroud)
.pdf中的文本要大得多,图形也很狭窄.但是,如果我将eps的大小单位更改为cm:
set terminal postscript eps enhanced colour size 10cm,8cm font 'Arial-Bold,14'
########
set output 'my_eps.eps'
set title 'My plot'
plot sin(x) notitle
set terminal pdfcairo size 10in,8in font 'Arial-Bold,14'
set output 'my_pdf.pdf'
replot
Run Code Online (Sandbox Code Playgroud)
使用错误的单位输出看起来相同(在一些边际误差内).这是巧合吗?这里发生了什么?
这是针对Gnuplot 4.4(补丁级别3)Ubuntu 11.10进行测试的.
(我知道我可以使用一些实用程序在eps和pdf之间进行转换,所以它们会是相同的,但我想了解gnuplot中发生了什么.)
我正在打印一大堆数字作为.png文件.每个图都是数据矩阵中一列的图,我将.png文件和它们串在一起形成一个动画.
我的问题是前几百张图像打印速度很快,但创建每个新图形的时间会迅速增加,从前几百个.png文件的~0.2秒增加到大约800个图像的2秒或更多.
在脚本运行期间内存使用量会增加,但每隔几秒左右只会增加1MB.这是在Windows上运行R2009b 64位.
我的代码看起来像:
n = 1000;
matrix = rand(n);
f = figure('Visible','off'); % create the figure
for i_ =1:n
plot(1:n,matrix(:,i_));
ylim([0 1]);
set(f,'PaperUnits','inches','PaperPosition',[0 0 6 4]);
png_name = [ 'img/timestep_' sprintf('%05d',i_) ];
print('-dpng', png_name);
end
Run Code Online (Sandbox Code Playgroud) 我正在 gnuplot 中绘制大量文件的创建时间,以查看它们是否按时间线性创建(它们不是)。
这是我的代码:
#!/bin/bash
stat -c %Y img2/*png > timedata
echo "set terminal postscript enhanced colour
set output 'file_creation_time.eps'
plot 'timedata'" | gnuplot
Run Code Online (Sandbox Code Playgroud)
我的问题是 y 数据是自 unix 开始时间以来的创建时间(以秒为单位),因此该图在 y 轴上只有 1.333...e+09。我想让第一个文件的创建时间缩放为零,以便相对创建时间是可读的。
我在许多数据绘图上下文中都遇到了这个问题,因此我希望能够在 gnuplot 中执行此操作,而不是诉诸 awk 或某些实用程序来预处理数据。
我知道第一次将是最小的,因为文件是按顺序命名的,所以有没有办法访问文件中的第一个元素,比如
`plot 'data' using ($1-$1[firstelement])`
Run Code Online (Sandbox Code Playgroud)
?
我正在 gnuplot 中的 multiplot 中寻找缩放选项。我可以使用set mouse Zoomjump放大正常的 gnuplot 。但它不适用于多重绘图。关于如何放大多图有什么想法吗?我正在将命令从 C++ 程序发送到 gnuplot。
谢谢
更新:此问题已在gnuplot的较新版本(> 5.0)中得到解决; 看@andyras的回答.
我很难让gnuplot在非postscript终端中创建带有粗体和增强文本的标签.以下脚本
#!/usr/bin/env gnuplot
reset
set terminal pdfcairo enhanced color lw 3 size 3,2 font 'Arial-Bold'
set output 'output.pdf'
set tics scale 0
plot -x title 'normal text', \
-2*x t 'enhanced_{text}', \
-3*x t '{/Arial-Bold attempt to specify_{font}}'
set terminal pngcairo enhanced color lw 3 size 400,300 font 'Arial-Bold'
set output 'output.png'
replot
set terminal postscript enhanced color lw 3 size 6,4 font 'Arial-Bold'
set output 'output.eps'
replot
reset
Run Code Online (Sandbox Code Playgroud)
生成以下eps(转换为png convert output.eps -rotate 90 outputeps.png):

这很好.但是,当我使用pdf或png终端时,结果如下所示: …
所以我想从一个数据文件中进行绘图,该文件具有不确定数量的 x 和 y 数据字段(未知但长度恒定)。我想将它们全部绘制在一张图表上,但使用不同的颜色。
在不指定索引的情况下,它们都以相同的颜色绘制在一起。
在索引上使用 for 循环或单独编写索引确实可以用不同的颜色将它们绘制在一起,但程序不会知道要循环多少个索引。
为 for 循环的最大值设置一个非常高的数字是可行的,但当数据用完时会发出错误消息。
有没有什么方法可以操作 gnuplot 中的数据来导出 for 循环的索引数量?
我试图在运行CentOS 6.4的几台计算机上比较已安装软件包的列表.输出yum list installed没有很好地排列成三列,例如:
ImageMagick.x86_64 6.5.4.7-6.el6_2 @base
MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201303020151.x86_64/6.4
ModemManager.x86_64 0.4.0-3.git20100628.el6
@anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager.x86_64 1:0.8.1-43.el6 @anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager-glib.x86_64
1:0.8.1-43.el6 @anaconda-CentOS-201303020151.x86_64/6.4
长行被包装以适合80列,这意味着如果我sort这个文件的某些包的信息将被扰乱.. 是否有一个简单的awk命令来获取此输出并每行打印三个字段?
我试过搜索类似的例子,但我只找到人们将一条长行拆分成列的情况.
我正在尝试grep文件中的行,其中一个单词以逗号后面的'ing'结尾,紧接着以下形式:
... we gave the dog a bone, showing great generosity ...
... this man, having no home ...
Run Code Online (Sandbox Code Playgroud)
但不是:
... this is a great place, we are having a good time ...
Run Code Online (Sandbox Code Playgroud)
我想找到"ing"字是逗号后面的第一个单词的实例.看起来这应该是非常可行的grep,但我还没弄清楚如何,或找到一个类似的例子.
我试过了
grep -e ", .*ing"
Run Code Online (Sandbox Code Playgroud)
它匹配逗号后面的多个单词.像这样的命令
grep -i -e ", [a-z]{1,}ing"
grep -i -e ", [a-z][a-z]+ing"
Run Code Online (Sandbox Code Playgroud)
不要做我所期望的 - 他们不像我前两个例子那样匹配短语.任何帮助(或指向更好的工具)将非常感激.