/*** Begin myExample.java ***/ class myExample { private double x; myExample(double newX) { x = newX; } public double getX() { return x; } public void setX(double newX) { x = newX; } public String toString() { return "### myExample: x = " +x +" ###"; } } /*** End myExample.java ***/
Compile myExample.java, and place the generated myExample.java file on MATLAB's classpath: see "Running your own class files in MATLAB" for details. Now, run it as follows:
» java on » x = myExample(32); » x.getX ans = 32 » x.setX(89) » x.getX ans = 89 » x.setX(11) » x.getX ans = 11 »
Back to Index |
![]() ![]() |