how can set values to a const mxArray ?
古いコメントを表示
Hi all, Suppose defined a const mxArray *ptr[2]. I wanna set *ptr[0] to a string such as 'mystr', and set *ptr[1] to a int varible such as 10. how can I do it? for example help me to modify this code:
const mxArray *prhs[2]; char a = 'mystr'; prhs[0] = a; prhs[1] = 10;
採用された回答
その他の回答 (3 件)
mxArray *prhs[2] is a field of pointers to mxArrays. The elements must be pointers to mxArrays then, not a pointer to a string or even an integer value directly.
Even char a='mystr' will fail, because a must be a pointer to a char, when it should carry a string in C.
I assumed there is a confusion with the names prhs and prh.
These are such fundamental problems concerning C that I do not think, that a solution will really help. You have to understand the bascic of C at first, befaore you can use it securely. And afterwards you can include the functionality of Matlab arrays. Read the C-Mex examples shipped with Matlab carefully to learn more details.
4 件のコメント
omid jab
2013 年 5 月 6 日
José-Luis
2013 年 5 月 6 日
You are still not answering any of the other comments.
James Tursa
2013 年 5 月 6 日
編集済み: James Tursa
2013 年 5 月 6 日
@omid jab: Here is the code. However, I am of the same opinion as Jan that these two lines may solve your stated problem in this post, but it is likely that they in and of themselves will not solve your overall problem, and that you likely need to learn C and go though the mex examples in the doc to know how to use these lines.
prhs[0] = mxCreateString("mystr");
prhs[1] = mxCreateDoubleScalar(10);
omid jab
2013 年 5 月 6 日
Azzi Abdelmalek
2013 年 5 月 6 日
編集済み: Azzi Abdelmalek
2013 年 5 月 6 日
prh{1}='mystr' % Matlab does not allow 0 as index (it must be logical or positive integer)
prh{2}=10
カテゴリ
ヘルプ センター および File Exchange で Write C Functions Callable from MATLAB (MEX Files) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!