Saving MULTI-Dimensonal Structure Data: from Matalb to Mex Fortran INPUTS-

1 vue (au cours des 30 derniers jours)
Rick
Rick le 17 Nov 2014
Commenté : Rick le 18 Nov 2014
Gang, I can pass and save a single structure of data in my Mex fortran file. My problem is how do I save multidimensional structure data.... Right now it is only saving the LAST dimension of data...
This is what I have in my Fortran file. The problem with this is only THE LAST array of inputs gets saved in ALL indexes.
% code
Do II = 1,10
Do JJ = 1,5
tmp = mxGetField(prhs(1),JJ,'Time')
call mxCopyPtrToReal4(mxGetData(tmp),Data_Block(II,JJ)%Time,1)
EndDo
EndDo
So what happens is 'Time' is ALL the same value for ALL indexes of the Data_Block Strucure..
The II or JJ indexes doesn't seem to increment or something.... Any Help ????

Réponse acceptée

Geoff Hayes
Geoff Hayes le 17 Nov 2014
Rick - your code to get the time data from the structure depends only on JJ
tmp = mxGetField(prhs(1),JJ,'Time')
Why are you not using II as well?
What does your input data look like? Are all time fields distinct?
  7 commentaires
Geoff Hayes
Geoff Hayes le 18 Nov 2014
Rick - I created some dummy test data as
Block_Data = [];
for k=1:10
Block_Data(k).GROUP1 = [];
for j=1:5
Block_Data(k).GROUP1(j).time = double(100*k+j);
end
end
Now in the main body of the Fortran code, I did the following
C get the size of the input array.
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
C iterate over each column (GROUP1)
Do n = 1,ncols
C get the field GROUP1
gmx = mxGetField(prhs(1),n,"GROUP1")
C get the dimensions of the GROUP1
gmrows = mxGetM(gmx)
gncols = mxGetN(gmx)
C iterate over each column (time)
Do gn = 1,gncols
C get the time data
tmx = mxGetPr(mxGetField(gmx,gn,"time"))
call mxCopyPtrToReal8(tmx,tmx_input,1)
C write the time data to the console
write(line,*) 'time = ',tmx_input
k=mexPrintf(line//achar(13))
EndDo
EndDo
Once I compiled the code (with the above body), I ran the function as
Call_Wrapper(Block_Data)
and I observed all the correct times being written to the console. Try incorporating the above code/logic into your program, substituting the "write" commands with that which updates your array.
Rick
Rick le 18 Nov 2014
Thank you Thank you......... I will try this later......... and get back with you..........Thank you for all your time I have taken up...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by