问题如下:
我有一个抽象类型MyAbstract和派生的复合类型MyType1和MyType2:
abstract MyAbstract
type MyType1 <: MyAbstract
somestuff
end
type MyType2 <: MyAbstract
someotherstuff
end
Run Code Online (Sandbox Code Playgroud)
我想为类型的对象指定一些一般行为MyAbstract,所以我有一个函数
function dosth(x::MyAbstract)
println(1) # instead of something useful
end
Run Code Online (Sandbox Code Playgroud)
这种一般行为足以满足MyType1但是当dosth使用类型的参数调用时MyType2,我想要一些特定的其他事情MyType2,当然,我想重用现有的代码,所以我尝试了以下,但它没有用:
function dosth(x::MyType2)
dosth(x::MyAbstract)
println(2)
end
x = MyType2("")
dosth(x) # StackOverflowError
Run Code Online (Sandbox Code Playgroud)
这意味着朱莉娅x有一段时间没有认识到我试图像对待它的"超类型"一样.
是否可以从Julia中的覆盖函数调用重载函数?我怎样才能优雅地解决这个问题?
我希望获得像在 Julia REPL 中作为字符串打印一样的输出,而不是打印到 REPL。
考虑你有一个大矩阵x。
x = rand(100, 100)
Run Code Online (Sandbox Code Playgroud)
在 REPL 中,x 以一种很好的方式显示。我想通过函数调用将此输出作为字符串获取(不是以黑客的方式)。我怎样才能做到这一点?
我尝试使用该函数repr来获取输出:
repr(x)
Run Code Online (Sandbox Code Playgroud)
这给出了一个非常长的字符串,包含所有数字并且使屏幕变得混乱。我尝试使用这个context论点。首先用钥匙displaysize:
repr(x, context = :displaysize => (80,80))
Run Code Online (Sandbox Code Playgroud)
它没有任何效果。(?)我尝试使用密钥limit:
repr(x, context = :limit => true)
Run Code Online (Sandbox Code Playgroud)
这给出的输出不再使屏幕混乱,但它看起来不如“正常”REPL 输出那么好。
我尝试了同样的print功能和IOContext
io = IOBuffer();
print(IOContext(io, :limit => true), x)
String(take!(io))
Run Code Online (Sandbox Code Playgroud)
这给出了与 相同的结果repr。
当我将Primefaces SelectOneMenu放在Primefaces Input旁边时,它们在浏览器中的高度不同(在Firefox,IE和Chrome中也是如此):
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head />
<h:body>
<p:selectOneMenu>
<f:selectItem itemLabel="Item1" />
</p:selectOneMenu>
<p:inputText value="Text" />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
是否可以(使用css)将这两个输入彼此相邻放置,以便它们可以在同一垂直位置的一行中显示?
(我使用Primfaces 5.1.)
我想出了如何使用包“Gadfly”和以下代码绘制带有不对称“丝带”的折线图
x=collect(-10:10);
y=[i^2 for i in -10:10];
ymin = y-5;
ymax = y+10;
using Gadfly
plot(x=x, y=y, ymin=ymin, ymax=ymax, Geom.smooth, Geom.ribbon)
Run Code Online (Sandbox Code Playgroud)
(这是在这个问题中描述的 。)
现在我想使用plot“Plots”包的功能来做同样的事情。有选项ribbon和fillrange(参见http://plots.readthedocs.io/en/latest/examples/pyplot/#layouts-margins-label-rotation-title-location)但我不知道如何使用它们。是否可以使用“Plots”包创建这样的图,如果是,如何创建?
在我的代码中,我有很多地方可以调用表单的函数
X = f(X)
Run Code Online (Sandbox Code Playgroud)
X可以是一个相当大的矩阵.在我的特殊情况下,我主要是打电话
X = feval(somefunc, X)
Run Code Online (Sandbox Code Playgroud)
要么
X = obj.myfunc(X)
Run Code Online (Sandbox Code Playgroud)
如果每次调用函数时都会为X分配新的空间,那将是不好的.MATLAB是否足够智能来处理这样的函数调用?有办法告诉吗?
这个问题的答案对于设计决策非常有帮助.我喜欢以面向对象的方式编程,如果MATLAB不够智能,那么在课堂上为X添加另一个成员可能会有所回报,尽管我宁愿不这样做.
我是 SAS 新手,但我正在准备一个解释一些基本 SAS 的讲座。我想展示如何使用 SAS(版本 9.4)创建条形图。为此,我使用 SAS 中的“heart”示例数据集。
如果我通过变量“Smoking_Status”创建条形图PROC FREQ,我会得到无用的条形排序。
proc freq data=sashelp.heart;
tables Smoking_Status / plots = freqplot;
run;
Run Code Online (Sandbox Code Playgroud)
PROC FREQ是否可以通过参数手动订购条形ORDER=?我不明白怎么办。我希望图表有很好的描述,而不是在标签前加上“1-”或“2-”前缀,以便能够按字母顺序对它们进行排序,因为这会降低结果图的可读性。
我可以通过 达到想要的结果SGPLOT。
proc sgplot data=sashelp.heart;
vbar Smoking_Status;
title "Distribution of smoking_status from sashelp.heart dataset";
xaxis display=(nolabel) values=('Non-smoker' 'Light (1-5)' 'Moderate (6-15)'
'Heavy (16-25)' 'Very Heavy (> 25)');
run;
Run Code Online (Sandbox Code Playgroud)
我的问题是:是否还有一种方法可以通过 实现此结果PROC FREQ?我想确定是否是这种情况,因为我想展示这个问题最简单、最直接的解决方案。