how to get the length of a array?
Ältere Kommentare anzeigen
I know mxGetM and mxGetN can get the row and col,and its parameter is a array name or a pointer.
But,I know when a array name act as a function parameter, it will behave just a pointer. for exmaple,
#
include <iostream>
using namespace std ;
int GetM(int* array)
{
return sizeof(array)/sizeof(array[0]) ;
}
int main()
{
int a[3] = {1,2,3} ;
cout<<GetM(a)<<endl ;
}
in this example ,GetM(a) return 1,not 3.so,I want to know how to realize matlab function mxGetM or how to get the length of a array. thanks a lot!
Akzeptierte Antwort
Weitere Antworten (1)
James Tursa
am 5 Jan. 2014
1 Stimme
Pass the length of the "array" as part of the argument list. You can't get this info by simply examining the "array" pointer itself as you are attempting. "a" is of type "array of 3 int's", but "array" is of type "pointer to int".
Kategorien
Mehr zu C Matrix API finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!