我试图从Mathematica中获取一张图片.
我尝试评估一些使用包中的方法生成图形的Mathematica代码.
如果我将代码粘贴到Mathematica Notebook,则会正确生成图形.
所以我的问题:
如何将这些图形转换为Java ???
这是我的示例代码:
ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'F:\\APPS\\Wolfram
Research\\Mathematica\\7.0\\mathkernel.exe'");
ml.addPacketListener(new MyPacketListener());
ml.discardAnswer();
PacketListener stdoutPrinter = new PacketPrinter(System.out);
ml.addPacketListener(stdoutPrinter);
// In stringList there is all the INPUT for Mathematica
for (int i = 0; stringList.size() > i; i++)
{
System.out.println("Input" + "[" + i + "]" + stringList.get(i));
ml.evaluate(stringList.get(i));
ml.discardAnswer();
}
ml.close();
class MyPacketListener implements PacketListener {
public boolean packetArrived(PacketArrivedEvent evt)
throws MathLinkException {
if (evt.getPktType() == MathLink.TEXTPKT) {
KernelLink ml = (KernelLink) evt.getSource();
System.out.println(ml.getString());
}
return true;
}
输出是:
<<CIP`ExperimentalData`
<<CIP`MLR`
dataSet = CIP`ExperimentalData`GetQSPRDataSet02[];
CIP`Graphics`ShowDataSetInfo[{"IoPairs", "InputComponents", "OutputComponents"},
dataSet];
Number of IO pairs = 2169
Number of input components = 130
Number of output components = 1
mlrInfo = CIP`MLR`FitMlr[dataSet];
mlrInfoInInputForm = InputForm[mlrInfo];
pointSize = 0.025;
CIP`MLR`ShowMlrSingleRegression[{"ModelVsDataPlot", "CorrelationCoefficient"},
dataSet, mlrInfo, GraphicsOptionPointSize -> pointSize];
(*-Graphics-*)
(*
Out 1 : Correlation coefficient = 0.999373
*)
pointSize = 0.01;
CIP`MLR`ShowMlrSingleRegression[{"AbsoluteSortedResidualsPlot",
"AbsoluteResidualsStatistics", "RMSE"},
dataSet, mlrInfo, GraphicsOptionPointSize -> pointSize];
(*-Graphics-
Definition of 'Residual (absolute)': Data - Model
-1
Out 1 : Residual (absolute): Mean/Median/Maximum Value = 1.4 / 9.84 × 10 /
1
> 1.79 × 10
Root mean squared error (RMSE) = 2.063
*)
我如何获得这些-Graphics-?
谢谢您的帮助!
解决方法:
J / Link用户指南有很好的代码示例,用于将图形从Mathematica发送到Java:
http://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html#29556