Re: pass 1D vector from matlab to fortran



On Mon, 31 Dec 2007 07:16:03 +0000 (UTC), "Eric Jäger"
<eric.jaeger.nospam@xxxxxxxxxxxxx> wrote:

I only have an example code for passing a 2D matrix from
matlab to fortran (and then again back to matlab):

plhs(1)=mxCreateNumericArray(2,[10;100],mxClassIDFromClassName('double'),0)
output1=mxGetPr(plhs(1))

%Call Fortran code
call_stl(%val(input1),%val(input2),%val(output1))

How do I have to change the code to pass an 1D vector (lets
say size: 1*1000) from matlab to fortran?

If you have working code for a 2D matrix, you should be able to just
replace the dimension values 10 & 100 with your new values 1 & 1000
and it should work just fine, even if the Fortran variable is only one
dimension. A 1D variable in MATLAB is treated as 2D with one of the
dimensions 1 (a scalar is a 2D with both of the dimensions 1). You
don't show much code for your example so I can't give you specific
advice. What are input1 and input2? Are they the result of another
mxGetPr call somewhere in your code? Is your call_stl(...) working for
2D? etc. etc.

James Tursa
.



Relevant Pages

  • Re: MATLAB <-> FORTRAN
    ... When you do A\b it just calls the basic solvers Matlab knows, ... in some cases Gauss Elimination. ... In this case you can find a Gauss Solver, ... I've bitten the bullet and converted to Fortran ...
    (comp.soft-sys.matlab)
  • Re: Matlab Vectorisation Speed - How is it done in c++?
    ... Beating the performance of vectorized Matlab code is very ... Matlab makes calls to optimized C and Fortran libraries ... Use optimization level 3 on numerical code and level 2 on non- ...
    (comp.soft-sys.matlab)
  • Re: Calling MATLAB from Fortran
    ... Fortran saves the data which Matlab m-file needs and then Matlab would read them as input from the file and after calculation save then in a file for Fortran. ... returns mxArray * ...
    (comp.soft-sys.matlab)
  • Re: mex in matlab from fortran
    ... driver subroutine. ... beginning of the fortran and then put the statements ... Now when I call the matlab ... James Tursa ...
    (comp.soft-sys.matlab)
  • Re: pass 1D vector from matlab to fortran
    ... matlab to fortran: ... %input: timeseries ts and constants ... polynomial in seasonal smoothing ...
    (comp.soft-sys.matlab)