Prev: esperanc
Next: mxstruct filling
From: Ashish Uthama on 17 Mar 2010 15:19 On Wed, 17 Mar 2010 04:47:22 -0400, Sergio <serjossj(a)inwind.it> wrote: > "Ashish Uthama" <first.last(a)mathworks.com> wrote in message < >> Serjo, >> Could you explain your setup some more? >> It is not clear if you are trying to pass a structure from C++ Mex >> file to MATLAB. Or, if you have a C++ application which uses a MATLAB >> code compiled into a DLL. I believe its the latter, in which case, >> yes, the DLL will create its own instance of 'MATLAB' (Look up MCR in >> the doc). It will not have access to your interactive MATLAB session's >> workspace. >> Note that mxArray are C/C++ source code for Mex files for use in a >> MATLAB session, mwArray are for C++ source code for drivers to use >> MATLAB compiled DLLs >> > > Hi, > I've a MATLAB code compiled in a dll so i need to convert that struct as > input argument. > I managed to create that struct directly in an mwArray but, i'm having > some problem with filling it. Here is the code: > > const char* fields[] = {"latitude", "longitude", "altitude"}; > mwArray entitylist(1, Total_entities, 3, fields) > mwArray temp(1,1,mxDOUBLE_CLASS); > double a; > > for (int i_list = 1; i_list<=Total_entities; i_list++) > { > a = latitude; > temp.SetData(&a,1); > entitylist.Get("latitude",1,i_list).Set(temp); > } > while filling mwArray entitylist, just last value is loaded even if > column index is specified by i_list. (ie, if i've Total entities equal > to 3, just last latitude value is loaded into entitylist.latitude and it > fills all 3 columns. Am i doing something wrong? > > Thx Your code appears to be doing exactly what you observe. I dont see the value of 'a' changing inside the loop, I would expect entitylist.latitude to have same valued elements.
From: Sergio on 18 Mar 2010 05:59
> > const char* fields[] = {"latitude", "longitude", "altitude"}; > > mwArray entitylist(1, Total_entities, 3, fields) > > mwArray temp(1,1,mxDOUBLE_CLASS); > > double a; > > > > for (int i_list = 1; i_list<=Total_entities; i_list++) > > { > > a = latitude; > > temp.SetData(&a,1); > > entitylist.Get("latitude",1,i_list).Set(temp); > > } > Your code appears to be doing exactly what you observe. > I dont see the value of 'a' changing inside the loop, I would expect > entitylist.latitude to have same valued elements. but i_list change within for cycle and, with each for cycle i've a different latitude value. so, i would set a different value of latitude (this is not an array but change accordingly to entity, outside for cycle). So, i thought i might fill it just by chosing row and column index. btw, i found a mode to handle it: a = latitude; temp.Get(1,i_list).SetData(&a,1); entitylist.Get("latitude",1,i_list).Set(temp.Get(1,i_list)); in this way it seems struct is corerctly loaded. |