How to define a matrix with 5000 specific elements [closed]
Hello, I need to define a matrix M, M is 5000*2. In matlab, M=[1,45;89,3;....], it's not regular, so I can't define it in a loop. In my code I tried to define it like
Mat M = (Mat_<int>(num, 3) << 994, 323, 0, 4014, 4295, 4395, 4906, 3423, 2792.....);
But when I use
printf("number: %f", M.at<double>(2, 1)
,
it gives me 0.
So could anyone tell me how to define such a matrix like in matlab M=[1 2 3; 4 5 6;....]
to access a
Mat_<int>
, you have to useM.at<int>()
(obvious, isn't it ?)"it's not regular,"` -- what do you mean ?
Thank you. It worker. How stupid I was, forgot to change the data type. When I say"it's not regular", I mean that it's not random number, nor part a a progression, so I can't define it in a loop. I am not a native English speaker. So I may make mistakes. Anyway, thank you very much.
what about writing it into a file from matlab(say, csv), and reading it back in ? see e.g. here
Thank you. I will learn how to do it.