フィルターのクリア

Passing structures through mex

1 回表示 (過去 30 日間)
Justin
Justin 2012 年 1 月 13 日
Ok. I have a structure I want to have access to in my mex file (which I'm writing in C). The values are located in a field within a field (fieldception). Here's an explicit example:
I want to access:
sys.gen.window_size
Where window_size contains an array with the x and y size of a picture (i.e. sys.gen.window_size = size(picture)).
I know you're supposed to use mxGetField. Matlab help says I need to write the field name when sending a structure as an argument, but since the field is a subfield, would I just enter "gen.window_size?"
Or... should I just make life easier and rewrite the structure contain no subfields?
Thanks

採用された回答

James Tursa
James Tursa 2012 年 1 月 13 日
E.g., the following code snippet w/o any argument checking, assuming you pass in the structure sys as the first argument:
mxArray *gen, *window_size;
double *pr;
:
gen = mxGetField(prhs[0],0,"gen");
window_size = mxGetField(gen,0,"window_size");
pr = mxGetPr(window_size);
pr[0] and pr[1] are your window size values.
NOTE: gen and window_size are pointers to the original fields of your workspace variable. They are not copies, so be sure that you do not call mxDestroyArray on them when you are done.
  7 件のコメント
Justin
Justin 2012 年 1 月 15 日
Thanks again!
Jan
Jan 2012 年 1 月 15 日
@Justin: Is the problem solved now? Then please accept the answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by