matlab - Inputting values from .mat file to array in C++ -
i trying copy 1100x1100 matrix .mat file array variable of type float in c++. read online , found matio library option. installed library using "make" on ubuntu 12.04 (i followed method given on webpage). however, unable write code using because new c++. using g++ compile file. errors such "unknown reference mat_open" , on. did find bit of code on webpage:
#include <stdlib.h> #include <stdio.h> #include "matio.h" int main(int argc,char **argv) { mat_t *matfp; matvar_t *matvar; matfp = mat_open(argv[1],mat_acc_rdonly); //here argv[1] "a.mat"? if ( null == matfp ) { fprintf(stderr,"error opening mat file %s0,argv[1]); return exit_failure; } matvar = mat_varreadinfo(matfp,"x"); // x variable trying access? if ( null == matvar ) { fprintf(stderr,"variable ’x’ not found, or error reading mat file\n"); } i have couple of questions:
- here, argv[1] corresponds .mat file trying open right?
- x in code variable present in .mat file trying copy?
- when ran code, received errors stating - unknown reference mat_open , on. couple of same type of errors there.
i compiled using : g++ abc.cpp -o test. (followed ./test. never got around due errors obtained during compilation).
how can make work? there mistake code used? or compile statement using-maybe there linkers need use compilation.
thank you. please remember new c++. advice helpful.
1) argv[1] - first parameter put after program call. if want "feel it", use debugger or code this:
#include <iostream> (unsigned = 0; < argc; ++i) { std::cout << argv[i] << std::endl; } 2) yes, looking @ http://libmatio.sourcearchive.com/documentation/1.3.4/group__mat_g4c8205ff25c5b688a40775fbb1840b7e.html can say, read variable name "x".
3) "undefined reference" means need build matio libraries. add "-llibraryname" compile string. , have built.
to avoid many problems, try install code::blocks, it's cross-platform , quite easy start using c++ if never did before. supports debuggers, avoid many problems quite easy.
Comments
Post a Comment