how to get the length of a array?
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (1)
James Tursa
el 5 de En. de 2014
1 voto
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".
Categorías
Más información sobre C Matrix API en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!