Saving MULTI-Dimensonal Structure Data: from Matalb to Mex Fortran INPUTS-
조회 수: 2 (최근 30일)
이전 댓글 표시
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 ????
댓글 수: 0
채택된 답변
Geoff Hayes
2014년 11월 17일
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
Geoff Hayes
2014년 11월 18일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 External Language Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!