|
41 | 41 | import javax.script.Bindings; |
42 | 42 |
|
43 | 43 | import matlabcontrol.MatlabInvocationException; |
| 44 | +import matlabcontrol.extensions.MatlabNumericArray; |
| 45 | +import matlabcontrol.extensions.MatlabTypeConverter; |
44 | 46 |
|
45 | 47 | /** |
46 | 48 | * A {@link Bindings} wrapper around MATLAB's local variables. |
@@ -104,7 +106,20 @@ public Object put(final String name, final Object value) { |
104 | 106 | return value; |
105 | 107 | } |
106 | 108 | catch (final MatlabInvocationException e) { |
107 | | - // TODO throw exception/print error - |
| 109 | + |
| 110 | + // Try special MATLAB data types |
| 111 | + if (MatlabNumericArray.class.isAssignableFrom(value.getClass())) { |
| 112 | + // Convert the dataset to a MATLAB array and set it as a local variable |
| 113 | + // within MATLAB. |
| 114 | + final MatlabTypeConverter converter = |
| 115 | + new MatlabTypeConverter(MATLABControlUtils.proxy()); |
| 116 | + try { |
| 117 | + converter.setNumericArray(name, (MatlabNumericArray) value); |
| 118 | + } |
| 119 | + catch (MatlabInvocationException e1) { |
| 120 | + throw new IllegalArgumentException(e); |
| 121 | + } |
| 122 | + } |
108 | 123 | } |
109 | 124 | return null; |
110 | 125 | } |
@@ -150,7 +165,19 @@ private Object retrieveValue(final Object key, final boolean remove) { |
150 | 165 | v = MATLABControlUtils.proxy().getVariable(k); |
151 | 166 | if (remove) MATLABControlUtils.proxy().eval("clear " + k); |
152 | 167 | } |
153 | | - catch (final MatlabInvocationException e) {} |
| 168 | + catch (final MatlabInvocationException e) { |
| 169 | + |
| 170 | + // Attempt to retrieve special MATLAB types |
| 171 | + try { |
| 172 | + // try recovering key as a MatlabNumericArray |
| 173 | + final MatlabTypeConverter converter = |
| 174 | + new MatlabTypeConverter(MATLABControlUtils.proxy()); |
| 175 | + v = converter.getNumericArray(k); |
| 176 | + } |
| 177 | + catch (final MatlabInvocationException e1) { |
| 178 | + System.err.println(e.getStackTrace()); |
| 179 | + } |
| 180 | + } |
154 | 181 | return v; |
155 | 182 | } |
156 | 183 |
|
|
0 commit comments