{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Matlab API","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":false}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"matlab-api","__idx":0},"children":["Matlab API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Matlab API can be used to execute commands, functions, scripts, send and pull data from a MATLAB environment. A ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/intviewer/intviewer-tutorial/using-intviewer-components-walkthroughs/using-the-matlab-api"},"children":["walkthrough"]}," is available to send a trace to MATLAB."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"getting-the-matlab-proxy","__idx":1},"children":["Getting the Matlab Proxy"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The IMatlabProxy object is what is used to communicate with MATLAB. Before an instance of this object can be used INTViewer must already be connected to MATLAB."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code below creates an instance of the IMatlabProxy object."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    IMatlabProxy proxy = IMatlabConnector.Factory.getInstance().getProxy();\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sending-a-trace","__idx":2},"children":["Sending a trace"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using a IMatlabProxy instance created like above we can now send data to MATLAB."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"            ISeismicData seismicData = (ISeismicData) IData.factory.createNewInstance(\"mySeismicData.xgy\");\n            ISeismicReader seismicReader= seismicData.select(new SeismicRangeQuery());\n            ITrace trace = seismicReader.getTrace(0);\n            float[] samples = new float[trace.getSize()];\n            trace.getSamples(samples); \n            proxy.setVariable(\"trace0\", samples);\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"getting-a-trace","__idx":3},"children":["Getting a trace"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using the \"trace0\" variable crated above:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"                 float[] matlabSamples = (float[]) proxy.getVariable(\"trace0\");\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sending-a-volume","__idx":4},"children":["Sending a volume"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"        ISeismicData seismicData = (ISeismicData) IData.factory.createNewInstance(\"mySeismicData.xgy\");\n        IKeyRange inlineKey = seismicData.getDataRange().get(0);\n        IKeyRange xlineKey = seismicData.getDataRange().get(1);\n        ISeismicReader reader = seismicData.select(new SeismicRangeQuery()); //select all data\n        IFieldDesc inlineFieldDesc = reader.getTraceHeaderField(inlineKey.getName());\n        IFieldDesc xlineFieldDesc = reader.getTraceHeaderField(xlineKey.getName());\n        int numInlines = (int) (inlineKey.getMaximum() - inlineKey.getMinimum())+1;\n        int numXlines = (int) (xlineKey .getMaximum() - xlineKey .getMinimum())+1;\n        int numberOfSamples = reader.getDataStatistics().getSamplesPerTrace();\n        int numberOfTraces = reader.getNumberOfTraces();\n        double[][][] volumeData = new double[numInlines][numXlines][numberOfSamples];\n        for (int i = 0; i < numberOfTraces; i++) {\n            ITrace trace = reader.getTrace(i);\n            float[] samples = new float[numberOfSamples];\n            trace.getSamples(samples);\n            int inline = trace.getHeader(inlineFieldDesc.getIdentifier()).intValue();\n            int xline = trace.getHeader(xlineFieldDesc.getIdentifier()).intValue();\n            for (int j = 0; j < samples.length; j++) {\n                int inlineIndex = inline - (int)inlineKey.getMinimum();\n                int xlineIndex = xline - (int)xlineKey.getMinimum();            \n                volumeData[inlineIndex][xlineIndex][j] = samples[j];\n            }\n        }\n        MatlabNumericArray matlabNumericArray = new MatlabNumericArray(volumeData, null);\n        proxy.setNumericArray(\"volume\", matlabNumericArray);\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note: This will not work for large seismic files, the data will have to be buffered in those cases."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"getting-a-volume","__idx":5},"children":["Getting a volume"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using the \"volume\" variable created above:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"        MatlabNumericArray numericArray = proxy.getNumericArray(\"volume\");\n        double[][][] matlabVolumeValues= numericArray.getRealArray3D();\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"executing-commands-in-matlab","__idx":6},"children":["Executing commands in MATLAB"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Simple commands"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using the same \"volume\" variable again, we divide every value by 2:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"                proxy.eval(\"volume = volume./ 2\");\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Commands that return values"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"               double[] returnedValues = (double[]) proxy.eval(\"length(volume)\", 1);\n"},"children":[]}]},"headings":[{"value":"Matlab API","id":"matlab-api","depth":1},{"value":"Getting the Matlab Proxy","id":"getting-the-matlab-proxy","depth":3},{"value":"Sending a trace","id":"sending-a-trace","depth":3},{"value":"Getting a trace","id":"getting-a-trace","depth":3},{"value":"Sending a volume","id":"sending-a-volume","depth":3},{"value":"Getting a volume","id":"getting-a-volume","depth":3},{"value":"Executing commands in MATLAB","id":"executing-commands-in-matlab","depth":3}],"frontmatter":{"title":"Matlab API","pageId":"other-useful-intviewer-apis/matlab-api","seo":{"title":"Matlab API"}},"lastModified":"2026-10-22T14:32:05.579Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/intviewer/other-useful-intviewer-apis/matlab-api","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}