Mex function, one or more output arguments not assigned

Hello,
I get the following error when trying to test my mex function "One or more output arguments not assigned during call to 'mymexfunction'". There should be 102 outputs from the function.
I do the following to copy the variables from the fortran code back to matlab
plhs(1) = mxcreatedoublematrix(m2,n2,0)
plhs(2) = mxcreatedoublematrix(m2,n2,0)
plhs(3) = mxcreatedoublematrix(m2,n2,0)
etc...
MRb1_1p_pr = mxgetpr(plhs(1))
MRb1_2p_pr = mxgetpr(plhs(2))
MRb1_3p_pr = mxgetpr(plhs(3))
etc...
call mxcopyreal8toptr(MarkersResults%Blade(1,1)%Position,MRb1_1p_pr,size2)
call mxcopyreal8toptr(MarkersResults%Blade(2,1)%Position,MRb1_2p_pr,size2)
call mxcopyreal8toptr(MarkersResults%Blade(3,1)%Position,MRb1_3p_pr,size2)
etc...
I try to get the results using the following syntax in my .m file
%[M1, M2, M3, etc..] = mymexfunction(var1, var2)

Risposte (1)

102 outputs is a LOT, and seems to me would be hard to maintain. Returning a single cell array would probably be a better approach.
That being said, I am not sure what the internal limit is for this. I know mexCallMATLAB has an internal limit of 50. There may be a similar limit for the plhs array. But assuming this is not an issue, do you really have 102 statements creating outpus from plhs(1) all the way through plhs(102)? Are these all behind some type of "if" check to make sure nlhs == 102? Are you sure you have 102 outputs in your m-file calling sequence?

5 Commenti

Hi James,
The fortran calculation is as follows:
AD_Init%Blade(:,:)%Position(1) = 0.0
AD_Init%Blade(:,:)%Position(2) = 0.0
DO IB = 1, NB
AD_Init%Blade(:,IB)%Position(3) = RElm(:) - HubRadius
END DO
! RELATIVE ORIENTATION OF BLADE ELEMENTS
DO IB = 1,NB
AD_Init%Blade(:,IB)%Orientation(1,1) = COS( TWIST(:) )
AD_Init%Blade(:,IB)%Orientation(2,1) = SIN( TWIST(:) )
AD_Init%Blade(:,IB)%Orientation(3,1) = 0.0
AD_Init%Blade(:,IB)%Orientation(1,2) = -1.*AD_Init%Blade(:,IB)%Orientation(2,1)
AD_Init%Blade(:,IB)%Orientation(2,2) = AD_Init%Blade(:,IB)%Orientation(1,1)
AD_Init%Blade(:,IB)%Orientation(3,2) = 0.0
AD_Init%Blade(:,IB)%Orientation(1,3) = 0.0
AD_Init%Blade(:,IB)%Orientation(2,3) = 0.0
AD_Init%Blade(:,IB)%Orientation(3,3) = 1.0
END DO
Where Blade(:,:) is a # elements by # of blades matrix. In this case there are 17 elements and 3 blades. I believe I would have to copy each value for the corresponding element/blade back to matlab for 102 total outputs.
And confirm to have 102 statements for plhs(#) I'm sure there is a more efficient way to do it but I don't know how.
If you post the declarations for AD_Init etc I can reply with code that will return a single cell or struct array back to MATLAB.
Hi James,
AD_Init is
TYPE(AllAeroMarkers) :: AD_Init
TYPE, PUBLIC :: AllAeroMarkers
TYPE(Marker), ALLOCATABLE :: Blade(:,:)
END TYPE AllAeroMarkers
TYPE, PUBLIC :: Marker
REAL(8) :: Position(3)
REAL(8) :: Orientation(3,3)
REAL(8) :: TranslationVel(3)
REAL(8) :: RotationVel(3)
END TYPE Marker
The AD_Init will only return position and orientation arrays for this part of the program.
Also is there a limit to the number of inputs you can have? If I have a nested struct for an input for a total of over a 100 inputs would that be a problem?
Hi James,
Were you able to write a code that returns a struct array? I'm still stuck on this part of the project.

Accedi per commentare.

Categorie

Richiesto:

il 23 Lug 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by