Saving MULTI-Dimensonal Structure Data: from Matalb to Mex Fortran INPUTS-
1 回表示 (過去 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 で Fortran with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!