00001
00029 #ifndef ITMEX_H
00030 #define ITMEX_H
00031
00032 #include <itpp/itbase.h>
00033 #include <mex.h>
00034
00035
00036 namespace itpp
00037 {
00038
00039
00040
00041
00042
00088
00089
00090
00091
00093 bin mxArray2bin(const mxArray *in);
00095 short mxArray2short(const mxArray *in);
00097 int mxArray2int(const mxArray *in);
00099 double mxArray2double(const mxArray *in);
00101 std::complex<double> mxArray2double_complex(const mxArray *in);
00103 std::string mxArray2string(const mxArray *in);
00104
00106 bvec mxArray2bvec(const mxArray *in);
00108 svec mxArray2svec(const mxArray *in);
00110 ivec mxArray2ivec(const mxArray *in);
00112 vec mxArray2vec(const mxArray *in);
00114 cvec mxArray2cvec(const mxArray *in);
00115
00117 bmat mxArray2bmat(const mxArray *in);
00119 smat mxArray2smat(const mxArray *in);
00121 imat mxArray2imat(const mxArray *in);
00123 mat mxArray2mat(const mxArray *in);
00125 cmat mxArray2cmat(const mxArray *in);
00126
00127
00128
00129
00130
00132 void bin2mxArray(const bin &in, mxArray *out);
00134 void short2mxArray(const short &in, mxArray *out);
00136 void int2mxArray(const int &in, mxArray *out);
00138 void double2mxArray(const double &in, mxArray *out);
00140 void double_complex2mxArray(const std::complex<double> &in, mxArray *out);
00142 void string2mxArray(const std::string &in, mxArray* &out);
00143
00145 void bvec2mxArray(const bvec &in, mxArray *out);
00147 void svec2mxArray(const svec &in, mxArray *out);
00149 void ivec2mxArray(const ivec &in, mxArray *out);
00151 void vec2mxArray(const vec &in, mxArray *out);
00153 void cvec2mxArray(const cvec &in, mxArray *out);
00154
00156 void bmat2mxArray(const bmat &in, mxArray *out);
00158 void smat2mxArray(const smat &in, mxArray *out);
00160 void imat2mxArray(const imat &in, mxArray *out);
00162 void mat2mxArray(const mat &in, mxArray *out);
00164 void cmat2mxArray(const cmat &in, mxArray *out);
00165
00166
00167
00168
00169
00171 void mxArray2Csvec(const mxArray *in, short *out);
00173 void mxArray2Civec(const mxArray *in, int *out);
00175 void mxArray2Cvec(const mxArray *in, double *out);
00177 void mxArray2Ccvec(const mxArray *in, double *out_real, double *out_imag);
00178
00180 void mxArray2Csmat(const mxArray *in, short **out);
00182 void mxArray2Cimat(const mxArray *in, int **out);
00184 void mxArray2Cmat(const mxArray *in, double **out);
00186 void mxArray2Ccmat(const mxArray *in, double **out_real, double **out_imag);
00187
00188
00189
00190
00191
00193 void Csvec2mxArray(short *in, mxArray *out);
00195 void Civec2mxArray(int *in, mxArray *out);
00197 void Cvec2mxArray(double *in, mxArray *out);
00199 void Ccvec2mxArray(double *in_real, double *in_imag, mxArray *out);
00200
00202 void Csmat2mxArray(short **in, mxArray *out);
00204 void Cimat2mxArray(int **in, mxArray *out);
00206 void Cmat2mxArray(double **in, mxArray *out);
00208 void Ccmat2mxArray(double **in_real, double **in_imag, mxArray *out);
00209
00215 bin mxArray2bin(const mxArray *in)
00216 {
00217 int size;
00218 double* temp = (double*) mxGetPr(in);
00219 if (temp == 0) mexErrMsgTxt("mxArray2bin: Pointer to data is NULL");
00220 size = mxGetNumberOfElements(in);
00221 if (size != 1) mexErrMsgTxt("mxArray2bin: Size of data is not equal to one");
00222
00223 return (((*temp) > 0.0) ? bin(1) : bin(0));
00224 }
00225
00226 short mxArray2short(const mxArray *in)
00227 {
00228 int size;
00229 double* temp = (double*) mxGetPr(in);
00230 if (temp == 0) mexErrMsgTxt("mxArray2short: Pointer to data is NULL");
00231 size = mxGetNumberOfElements(in);
00232 if (size != 1) mexErrMsgTxt("mxArray2short: Size of data is not equal to one");
00233
00234 return (short)(*temp);
00235 }
00236
00237 int mxArray2int(const mxArray *in)
00238 {
00239 int size;
00240 double* temp = (double*) mxGetPr(in);
00241 if (temp == 0) mexErrMsgTxt("mxArray2int: Pointer to data is NULL");
00242 size = mxGetNumberOfElements(in);
00243 if (size != 1) mexErrMsgTxt("mxArray2int: Size of data is not equal to one");
00244
00245 return (int)(*temp);
00246 }
00247
00248 double mxArray2double(const mxArray *in)
00249 {
00250 int size;
00251 double* temp = (double*) mxGetPr(in);
00252 if (temp == 0) mexErrMsgTxt("mxArray2double: Pointer to data is NULL");
00253 size = mxGetNumberOfElements(in);
00254 if (size != 1) mexErrMsgTxt("mxArray2double: Size of data is not equal to one");
00255
00256 return (*temp);
00257 }
00258
00259 std::complex<double> mxArray2double_complex(const mxArray *in)
00260 {
00261 int size;
00262 double* tempR = (double*) mxGetPr(in);
00263 double* tempI = (double*) mxGetPi(in);
00264
00265 if ((tempR == 0) && (tempI == 0)) mexErrMsgTxt("mxArray2double_complex: Pointer to data is NULL");
00266
00267 size = mxGetNumberOfElements(in);
00268 if (size != 1) mexErrMsgTxt("mxArray2double_complex: Size of data is not equal to one");
00269
00270 if (tempR == 0) {
00271 return std::complex<double>(0.0 , (*tempI));
00272 }
00273 else if (tempI == 0) {
00274 return std::complex<double>((*tempR), 0.0);
00275 }
00276 else {
00277 return std::complex<double>((*tempR), (*tempI));
00278 }
00279
00280 }
00281
00282 std::string mxArray2string(const mxArray *in)
00283 {
00284 if (in == 0)
00285 mexErrMsgTxt("mxArray2string: Pointer to data is NULL");
00286 std::string str = mxArrayToString(in);
00287 if (str.data() == 0)
00288 mexErrMsgTxt("mxArray2string: Could not convert mxArray to string");
00289 return str;
00290 }
00291
00292 bvec mxArray2bvec(const mxArray *in)
00293 {
00294 bvec out;
00295 int i, size;
00296 double* temp = (double*) mxGetPr(in);
00297 if (temp == 0) mexErrMsgTxt("mxArray2bvec: Pointer to data is NULL");
00298
00299 size = mxGetNumberOfElements(in);
00300 if (size == 0) mexErrMsgTxt("mxArray2bvec: Size of data is zero");
00301
00302 out.set_size(size, false);
00303
00304 for (i = 0; i < size; i++) {
00305 out(i) = (((*temp++) > 1e-5) ? bin(1) : bin(0));
00306 }
00307
00308 return out;
00309
00310 }
00311
00312 svec mxArray2svec(const mxArray *in)
00313 {
00314 svec out;
00315 int i, size;
00316 double* temp = (double*) mxGetPr(in);
00317 if (temp == 0) mexErrMsgTxt("mxArray2svec: Pointer to data is NULL");
00318
00319 size = mxGetNumberOfElements(in);
00320 if (size == 0) mexErrMsgTxt("mxArray2svec: Size of data is zero");
00321
00322 out.set_size(size, false);
00323
00324 for (i = 0; i < size; i++) {
00325 out(i) = (short)(*temp++);
00326 }
00327
00328 return out;
00329
00330 }
00331
00332 ivec mxArray2ivec(const mxArray *in)
00333 {
00334 ivec out;
00335 int i, size;
00336 double* temp = (double*) mxGetPr(in);
00337 if (temp == 0) mexErrMsgTxt("mxArray2ivec: Pointer to data is NULL");
00338
00339 size = mxGetNumberOfElements(in);
00340 if (size == 0) mexErrMsgTxt("mxArray2ivec: Size of data is zero");
00341
00342 out.set_size(size, false);
00343
00344 for (i = 0; i < size; i++) {
00345 out(i) = (int)(*temp++);
00346 }
00347
00348 return out;
00349
00350 }
00351
00352 vec mxArray2vec(const mxArray *in)
00353 {
00354 vec out;
00355 int i, size;
00356 double* temp = (double*) mxGetPr(in);
00357 if (temp == 0) mexErrMsgTxt("mxArray2vec: Pointer to data is NULL");
00358
00359 size = mxGetNumberOfElements(in);
00360 if (size == 0) mexErrMsgTxt("mxArray2vec: Size of data is zero");
00361
00362 out.set_size(size, false);
00363
00364 for (i = 0; i < size; i++) {
00365 out(i) = (*temp++);
00366 }
00367
00368 return out;
00369
00370 }
00371
00372 cvec mxArray2cvec(const mxArray *in)
00373 {
00374 cvec out;
00375 int i, size;
00376 double* tempR = (double*) mxGetPr(in);
00377 double* tempI = (double*) mxGetPi(in);
00378
00379 if ((tempR == 0) && (tempI == 0)) mexErrMsgTxt("mxArray2cvec: Pointer data is NULL");
00380
00381 size = mxGetNumberOfElements(in);
00382 if (size == 0) mexErrMsgTxt("mxArray2cvec: Size of data is zero");
00383
00384 out.set_size(size, false);
00385
00386 if (tempR == 0) {
00387 for (i = 0; i < size; i++) { out(i) = std::complex<double>(0.0, (*tempI++)); }
00388 }
00389 else if (tempI == 0) {
00390 for (i = 0; i < size; i++) { out(i) = std::complex<double>((*tempR++), 0.0); }
00391 }
00392 else {
00393 for (i = 0; i < size; i++) { out(i) = std::complex<double>((*tempR++), (*tempI++)); }
00394 }
00395
00396 return out;
00397
00398 }
00399
00400 bmat mxArray2bmat(const mxArray *in)
00401 {
00402 bmat out;
00403 int r, c, rows, cols;
00404 double* temp = (double*) mxGetPr(in);
00405 if (temp == 0) mexErrMsgTxt("mxArray2bmat: Pointer to data is NULL");
00406
00407 rows = mxGetM(in);
00408 if (rows == 0) mexErrMsgTxt("mxArray2bmat: Data has zero rows");
00409 cols = mxGetN(in);
00410 if (cols == 0) mexErrMsgTxt("mxArray2bmat: Data has zero columns");
00411
00412 out.set_size(rows, cols, false);
00413
00414 for (c = 0; c < cols; c++) {
00415 for (r = 0; r < rows; r++) {
00416 out(r, c) = (((*temp++) > 0.0) ? bin(1) : bin(0));
00417 }
00418 }
00419
00420 return out;
00421
00422 }
00423
00424 smat mxArray2smat(const mxArray *in)
00425 {
00426 smat out;
00427 int r, c, rows, cols;
00428 double* temp = (double*) mxGetPr(in);
00429 if (temp == 0) mexErrMsgTxt("mxArray2smat: Pointer to data is NULL");
00430
00431 rows = mxGetM(in);
00432 if (rows == 0) mexErrMsgTxt("mxArray2smat: Data has zero rows");
00433 cols = mxGetN(in);
00434 if (cols == 0) mexErrMsgTxt("mxArray2smat: Data has zero columns");
00435
00436 out.set_size(rows, cols, false);
00437
00438 for (c = 0; c < cols; c++) {
00439 for (r = 0; r < rows; r++) {
00440 out(r, c) = (short)(*temp++);
00441 }
00442 }
00443
00444 return out;
00445
00446 }
00447
00448 imat mxArray2imat(const mxArray *in)
00449 {
00450 imat out;
00451 int r, c, rows, cols;
00452 double* temp = (double*) mxGetPr(in);
00453 if (temp == 0) mexErrMsgTxt("mxArray2imat: Pointer to data is NULL");
00454
00455 rows = mxGetM(in);
00456 if (rows == 0) mexErrMsgTxt("mxArray2imat: Data has zero rows");
00457 cols = mxGetN(in);
00458 if (cols == 0) mexErrMsgTxt("mxArray2imat: Data has zero columns");
00459 out.set_size(rows, cols, false);
00460
00461 for (c = 0; c < cols; c++) {
00462 for (r = 0; r < rows; r++) {
00463 out(r, c) = (int)(*temp++);
00464 }
00465 }
00466
00467 return out;
00468
00469 }
00470
00471 mat mxArray2mat(const mxArray *in)
00472 {
00473 mat out;
00474 int r, c, rows, cols;
00475 double* temp = (double*) mxGetPr(in);
00476 if (temp == 0) mexErrMsgTxt("mxArray2mat: Pointer to data is NULL");
00477
00478 rows = mxGetM(in);
00479 if (rows == 0) mexErrMsgTxt("mxArray2mat: Data has zero rows");
00480 cols = mxGetN(in);
00481 if (cols == 0) mexErrMsgTxt("mxArray2mat: Data has zero columns");
00482 out.set_size(rows, cols, false);
00483
00484 for (c = 0; c < cols; c++) {
00485 for (r = 0; r < rows; r++) {
00486 out(r, c) = (*temp++);
00487 }
00488 }
00489
00490 return out;
00491
00492 }
00493
00494 cmat mxArray2cmat(const mxArray *in)
00495 {
00496 cmat out;
00497 int r, c, rows, cols;
00498 double* tempR = (double*) mxGetPr(in);
00499 double* tempI = (double*) mxGetPi(in);
00500
00501 if ((tempR == 0) && (tempI == 0)) mexErrMsgTxt("mxArray2cmat: Pointer to data is NULL");
00502
00503 rows = mxGetM(in);
00504 if (rows == 0) mexErrMsgTxt("mxArray2cmat: Data has zero rows");
00505 cols = mxGetN(in);
00506 if (cols == 0) mexErrMsgTxt("mxArray2cmat: Data has zero columns");
00507 out.set_size(rows, cols, false);
00508
00509 if (tempR == 0) {
00510 for (c = 0; c < cols; c++) { for (r = 0; r < rows; r++) { out(r, c) = std::complex<double>(0.0 , (*tempI++)); } }
00511 }
00512 else if (tempI == 0) {
00513 for (c = 0; c < cols; c++) { for (r = 0; r < rows; r++) { out(r, c) = std::complex<double>((*tempR++), 0.0); } }
00514 }
00515 else {
00516 for (c = 0; c < cols; c++) { for (r = 0; r < rows; r++) { out(r, c) = std::complex<double>((*tempR++), (*tempI++)); } }
00517 }
00518
00519 return out;
00520
00521 }
00522
00523 void double2mxArray(const double &in, mxArray *out)
00524 {
00525 double* temp = (double *) mxGetPr(out);
00526 if (temp == 0) mexErrMsgTxt("double2mxArray: Pointer to data is NULL");
00527
00528 *temp = (double) in;
00529 }
00530
00531 void double_complex2mxArray(const std::complex<double> &in, mxArray *out)
00532 {
00533 double* tempR = (double *) mxGetPr(out);
00534 double* tempI = (double *) mxGetPi(out);
00535 if (tempR == 0) mexErrMsgTxt("double_complex2mxArray: Pointer to real valued part is NULL");
00536 if (tempI == 0) mexErrMsgTxt("double_complex2mxArray: Pointer to imaginary valued part is NULL");
00537
00538 *tempR = (double) in.real();
00539 *tempI = (double) in.imag();
00540 }
00541
00542 void string2mxArray(const std::string &in, mxArray* &out)
00543 {
00544 if (in.data() == 0)
00545 mexErrMsgTxt("string2mxArray: Pointer to string is NULL");
00546 out = mxCreateString(in.data());
00547 if (out == 0)
00548 mexErrMsgTxt("string2mxArray: Could not convert string to mxArray");
00549 }
00550
00551 void bvec2mxArray(const bvec &in, mxArray *out)
00552 {
00553 double* temp = (double *) mxGetPr(out);
00554 if (temp == 0) mexErrMsgTxt("bvec2mxArray: Pointer to data is NULL");
00555 if (in.size() == 0) mexErrMsgTxt("bvec2mxArray: Size of data is zero");
00556 for (int i = 0; i < in.size(); i++) {
00557 if (in(i))
00558 *temp++ = 1.0;
00559 else
00560 *temp++ = 0.0;
00561 }
00562 }
00563
00564 void ivec2mxArray(const ivec &in, mxArray *out)
00565 {
00566 double* temp = (double *) mxGetPr(out);
00567 if (temp == 0) mexErrMsgTxt("ivec2mxArray: Pointer to data is NULL");
00568 if (in.size() == 0) mexErrMsgTxt("ivec2mxArray: Size of data is zero");
00569
00570 for (int i = 0; i < in.size(); i++) {
00571 *temp++ = (double) in(i);
00572 }
00573 }
00574
00575 void vec2mxArray(const vec &in, mxArray *out)
00576 {
00577 double* temp = (double *) mxGetPr(out);
00578 if (temp == 0) mexErrMsgTxt("vec2mxArray: Pointer to data is NULL");
00579 if (in.size() == 0) mexErrMsgTxt("vec2mxArray: Size of data is zero");
00580
00581 for (int i = 0; i < in.size(); i++) {
00582 *temp++ = (double) in(i);
00583 }
00584 }
00585
00586 void cvec2mxArray(const cvec &in, mxArray *out)
00587 {
00588 double* tempR = (double *) mxGetPr(out);
00589 double* tempI = (double *) mxGetPi(out);
00590 if (tempR == 0) mexErrMsgTxt("cvec2mxArray: Pointer to real valued part is NULL");
00591 if (tempI == 0) mexErrMsgTxt("cvec2mxArray: Pointer to imaginary valued part is NULL");
00592 if (in.size() == 0) mexErrMsgTxt("cvec2mxArray: Size of data is zero");
00593
00594 for (int i = 0; i < in.size(); i++) {
00595 *tempR++ = (double) in(i).real();
00596 *tempI++ = (double) in(i).imag();
00597 }
00598 }
00599
00600 void bmat2mxArray(const bmat &in, mxArray *out)
00601 {
00602 int rows, cols, r, c;
00603
00604 double* temp = (double *) mxGetPr(out);
00605 if (temp == 0) mexErrMsgTxt("bmat2mxArray: Pointer to data is NULL");
00606
00607 rows = in.rows();
00608 cols = in.cols();
00609 if (rows == 0) mexErrMsgTxt("bmat2mxArray: Data has zero rows");
00610 if (cols == 0) mexErrMsgTxt("bmat2mxArray: Data has zero columns");
00611
00612 for (c = 0; c < cols; c++) {
00613 for (r = 0; r < rows; r++) {
00614 if (in(r, c))
00615 *temp++ = 1.0;
00616 else
00617 *temp++ = 0.0;
00618 }
00619 }
00620
00621 }
00622
00623 void smat2mxArray(const smat &in, mxArray *out)
00624 {
00625 int rows, cols, r, c;
00626
00627 double* temp = (double *) mxGetPr(out);
00628 if (temp == 0) mexErrMsgTxt("smat2mxArray: Pointer to data is NULL");
00629
00630 rows = in.rows();
00631 cols = in.cols();
00632 if (rows == 0) mexErrMsgTxt("smat2mxArray: Data has zero rows");
00633 if (cols == 0) mexErrMsgTxt("smat2mxArray: Data has zero columns");
00634
00635 for (c = 0; c < cols; c++) {
00636 for (r = 0; r < rows; r++) {
00637 *temp++ = (double) in(r, c);
00638 }
00639 }
00640
00641 }
00642
00643 void imat2mxArray(const imat &in, mxArray *out)
00644 {
00645 int rows, cols, r, c;
00646
00647 double* temp = (double *) mxGetPr(out);
00648 if (temp == 0) mexErrMsgTxt("imat2mxArray: Pointer to data is NULL");
00649
00650 rows = in.rows();
00651 cols = in.cols();
00652 if (rows == 0) mexErrMsgTxt("imat2mxArray: Data has zero rows");
00653 if (cols == 0) mexErrMsgTxt("imat2mxArray: Data has zero columns");
00654
00655 for (c = 0; c < cols; c++) {
00656 for (r = 0; r < rows; r++) {
00657 *temp++ = (double) in(r, c);
00658 }
00659 }
00660
00661 }
00662
00663 void mat2mxArray(const mat &in, mxArray *out)
00664 {
00665 int rows, cols, r, c;
00666
00667 double* temp = (double *) mxGetPr(out);
00668 if (temp == 0) mexErrMsgTxt("mat2mxArray: Pointer to data is NULL");
00669
00670 rows = in.rows();
00671 cols = in.cols();
00672 if (rows == 0) mexErrMsgTxt("mat2mxArray: Data has zero rows");
00673 if (cols == 0) mexErrMsgTxt("mat2mxArray: Data has zero columns");
00674
00675 for (c = 0; c < cols; c++) {
00676 for (r = 0; r < rows; r++) {
00677 *temp++ = in(r, c);
00678 }
00679 }
00680
00681 }
00682
00683 void cmat2mxArray(const cmat &in, mxArray *out)
00684 {
00685 int rows, cols, r, c;
00686
00687 double* tempR = (double *) mxGetPr(out);
00688 double* tempI = (double *) mxGetPi(out);
00689 if (tempR == 0) mexErrMsgTxt("cvec2mxArray: Pointer to real valued part is NULL");
00690 if (tempI == 0) mexErrMsgTxt("cvec2mxArray: Pointer to imaginary valued part is NULL");
00691
00692 rows = in.rows();
00693 cols = in.cols();
00694 if (rows == 0) mexErrMsgTxt("cvec2mxArray: Data has zero rows");
00695 if (cols == 0) mexErrMsgTxt("cvec2mxArray: Data has zero columns");
00696
00697 for (c = 0; c < cols; c++) {
00698 for (r = 0; r < rows; r++) {
00699 *tempR++ = (double) in(r, c).real();
00700 *tempI++ = (double) in(r, c).imag();
00701 }
00702 }
00703
00704 }
00705
00706 void mxArray2Csvec(const mxArray *in, short *out)
00707 {
00708 double* temp = (double*) mxGetPr(in);
00709 if (temp == 0) mexErrMsgTxt("mxArray2Csvec: Pointer to data is NULL");
00710 int size = mxGetNumberOfElements(in);
00711 if (size == 0) mexErrMsgTxt("mxArray2Csvec: Size of data is zero");
00712 for (int i = 0; i < size; i++) { out[i] = (short)(*temp++); }
00713 }
00714
00715 void mxArray2Civec(const mxArray *in, int *out)
00716 {
00717 double* temp = (double*) mxGetPr(in);
00718 if (temp == 0) mexErrMsgTxt("mxArray2Civec: Pointer to data is NULL");
00719 int size = mxGetNumberOfElements(in);
00720 if (size == 0) mexErrMsgTxt("mxArray2Civec: Size of data is zero");
00721 for (int i = 0; i < size; i++) { out[i] = (int)(*temp++); }
00722 }
00723
00724 void mxArray2Cvec(const mxArray *in, double *out)
00725 {
00726 double* temp = (double*) mxGetPr(in);
00727 if (temp == 0) mexErrMsgTxt("mxArray2Cvec: Pointer to data is NULL");
00728 int size = mxGetNumberOfElements(in);
00729 if (size == 0) mexErrMsgTxt("mxArray2Cvec: Size of data is zero");
00730 for (int i = 0; i < size; i++) { out[i] = (*temp++); }
00731 }
00732
00733 void mxArray2Ccvec(const mxArray *in, double *out_real, double *out_imag)
00734 {
00735 double* tempR = (double*) mxGetPr(in);
00736 double* tempI = (double*) mxGetPi(in);
00737 if (tempR == 0) mexErrMsgTxt("mxArray2Ccvec: Pointer to real valued part is NULL");
00738 if (tempI == 0) mexErrMsgTxt("mxArray2Ccvec: Pointer to imaginary valued part is NULL");
00739 int size = mxGetNumberOfElements(in);
00740 if (size == 0) mexErrMsgTxt("mxArray2Ccvec: Size of data is zero");
00741 for (int i = 0; i < size; i++) { out_real[i] = (*tempR++); out_imag[i] = (*tempI++); }
00742 }
00743
00744 void mxArray2Csmat(const mxArray *in, short **out)
00745 {
00746 int r, c;
00747 double* temp = (double*) mxGetPr(in);
00748 if (temp == 0) mexErrMsgTxt("mxArray2Csmat: Pointer to data is NULL");
00749 int rows = mxGetM(in);
00750 if (rows == 0) mexErrMsgTxt("mxArray2Csmat: Data has zero rows");
00751 int cols = mxGetN(in);
00752 if (cols == 0) mexErrMsgTxt("mxArray2Csmat: Data has zero columns");
00753 for (c = 0; c < cols; c++) {
00754 for (r = 0; r < rows; r++) {
00755 out[r][c] = (short)(*temp++);
00756 }
00757 }
00758 }
00759
00760 void mxArray2Cimat(const mxArray *in, int **out)
00761 {
00762 int r, c;
00763 double* temp = (double*) mxGetPr(in);
00764 if (temp == 0) mexErrMsgTxt("mxArray2Cimat: Pointer to data is NULL");
00765 int rows = mxGetM(in);
00766 if (rows == 0) mexErrMsgTxt("mxArray2Cimat: Data has zero rows");
00767 int cols = mxGetN(in);
00768 if (cols == 0) mexErrMsgTxt("mxArray2Cimat: Data has zero columns");
00769 for (c = 0; c < cols; c++) {
00770 for (r = 0; r < rows; r++) {
00771 out[r][c] = (int)(*temp++);
00772 }
00773 }
00774 }
00775
00776 void mxArray2Cmat(const mxArray *in, double **out)
00777 {
00778 int r, c;
00779 double* temp = (double*) mxGetPr(in);
00780 if (temp == 0) mexErrMsgTxt("mxArray2Cmat: Pointer to data is NULL");
00781 int rows = mxGetM(in);
00782 if (rows == 0) mexErrMsgTxt("mxArray2Cmat: Data has zero rows");
00783 int cols = mxGetN(in);
00784 if (cols == 0) mexErrMsgTxt("mxArray2Cmat: Data has zero columns");
00785 for (c = 0; c < cols; c++) {
00786 for (r = 0; r < rows; r++) {
00787 out[r][c] = (*temp++);
00788 }
00789 }
00790 }
00791
00792 void mxArray2Ccmat(const mxArray *in, double **out_real, double **out_imag)
00793 {
00794 int r, c;
00795 double* tempR = (double*) mxGetPr(in);
00796 double* tempI = (double*) mxGetPi(in);
00797 if (tempR == 0) mexErrMsgTxt("mxArray2Cmat: Pointer to real valued part is NULL");
00798 if (tempI == 0) mexErrMsgTxt("mxArray2Cmat: Pointer to imaginary valued part is NULL");
00799 int rows = mxGetM(in);
00800 if (rows == 0) mexErrMsgTxt("mxArray2Cmat: Data has zero rows");
00801 int cols = mxGetN(in);
00802 if (cols == 0) mexErrMsgTxt("mxArray2Cmat: Data has zero columns");
00803 for (c = 0; c < cols; c++) {
00804 for (r = 0; r < rows; r++) {
00805 out_real[r][c] = (*tempR++);
00806 out_imag[r][c] = (*tempI++);
00807 }
00808 }
00809 }
00810
00811 void Csvec2mxArray(short *in, mxArray *out)
00812 {
00813 double* temp = (double *) mxGetPr(out);
00814 if (temp == 0) mexErrMsgTxt("Csvec2mxArray: Pointer to data is NULL");
00815 int size = mxGetNumberOfElements(out);
00816 if (size == 0) mexErrMsgTxt("Csvec2mxArray: Size of data is zero");
00817 for (int i = 0; i < size; i++) { *temp++ = (double) in[i]; }
00818 }
00819
00820 void Civec2mxArray(int *in, mxArray *out)
00821 {
00822 double* temp = (double *) mxGetPr(out);
00823 if (temp == 0) mexErrMsgTxt("Civec2mxArray: Pointer to data is NULL");
00824 int size = mxGetNumberOfElements(out);
00825 if (size == 0) mexErrMsgTxt("Civec2mxArray: Size of data is zero");
00826 for (int i = 0; i < size; i++) { *temp++ = (double) in[i]; }
00827 }
00828
00829 void Cvec2mxArray(double *in, mxArray *out)
00830 {
00831 double* temp = (double *) mxGetPr(out);
00832 if (temp == 0) mexErrMsgTxt("Cvec2mxArray: Pointer to data is NULL");
00833 int size = mxGetNumberOfElements(out);
00834 if (size == 0) mexErrMsgTxt("Cvec2mxArray: Size of data is zero");
00835 for (int i = 0; i < size; i++) { *temp++ = in[i]; }
00836 }
00837
00838 void Ccvec2mxArray(double *in_real, double *in_imag, mxArray *out)
00839 {
00840 double* tempR = (double *) mxGetPr(out);
00841 double* tempI = (double *) mxGetPi(out);
00842 if (tempR == 0) mexErrMsgTxt("Ccvec2mxArray: Pointer to real valued part is NULL");
00843 if (tempI == 0) mexErrMsgTxt("Ccvec2mxArray: Pointer to imaginary valued part is NULL");
00844 int size = mxGetNumberOfElements(out);
00845 if (size == 0) mexErrMsgTxt("Ccvec2mxArray: Size of data is zero");
00846 for (int i = 0; i < size; i++) { *tempR++ = in_real[i]; *tempI++ = in_imag[i]; }
00847 }
00848
00849 void Csmat2mxArray(short **in, mxArray *out)
00850 {
00851 int r, c;
00852 double* temp = (double *) mxGetPr(out);
00853 if (temp == 0) mexErrMsgTxt("Csmat2mxArray: Pointer to data is NULL");
00854 int rows = mxGetM(out);
00855 if (rows == 0) mexErrMsgTxt("Csmat2mxArray: Data has zero rows");
00856 int cols = mxGetN(out);
00857 if (cols == 0) mexErrMsgTxt("Csmat2mxArray: Data has zero columns");
00858 for (c = 0; c < cols; c++) {
00859 for (r = 0; r < rows; r++) {
00860 *temp++ = (short) in[r][c];
00861 }
00862 }
00863 }
00864
00865 void Cimat2mxArray(int **in, mxArray *out)
00866 {
00867 int r, c;
00868 double* temp = (double *) mxGetPr(out);
00869 if (temp == 0) mexErrMsgTxt("Cimat2mxArray: Pointer to data is NULL");
00870 int rows = mxGetM(out);
00871 if (rows == 0) mexErrMsgTxt("Cimat2mxArray: Data has zero rows");
00872 int cols = mxGetN(out);
00873 if (cols == 0) mexErrMsgTxt("Cimat2mxArray: Data has zero columns");
00874 for (c = 0; c < cols; c++) {
00875 for (r = 0; r < rows; r++) {
00876 *temp++ = (int) in[r][c];
00877 }
00878 }
00879 }
00880
00881 void Cmat2mxArray(double **in, mxArray *out)
00882 {
00883 int r, c;
00884 double* temp = (double *) mxGetPr(out);
00885 if (temp == 0) mexErrMsgTxt("Cmat2mxArray: Pointer to data is NULL");
00886 int rows = mxGetM(out);
00887 if (rows == 0) mexErrMsgTxt("Cmat2mxArray: Data has zero rows");
00888 int cols = mxGetN(out);
00889 if (cols == 0) mexErrMsgTxt("Cmat2mxArray: Data has zero columns");
00890 for (c = 0; c < cols; c++) {
00891 for (r = 0; r < rows; r++) {
00892 *temp++ = in[r][c];
00893 }
00894 }
00895 }
00896
00897 void Ccmat2mxArray(double **in_real, double **in_imag, mxArray *out)
00898 {
00899 int r, c;
00900 double* tempR = (double *) mxGetPr(out);
00901 double* tempI = (double *) mxGetPi(out);
00902 if (tempR == 0) mexErrMsgTxt("Ccmat2mxArray: Pointer to real valued part is NULL");
00903 if (tempI == 0) mexErrMsgTxt("Ccmat2mxArray: Pointer to imaginary valued part is NULL");
00904 int rows = mxGetM(out);
00905 if (rows == 0) mexErrMsgTxt("Ccmat2mxArray: Data has zero rows");
00906 int cols = mxGetN(out);
00907 if (cols == 0) mexErrMsgTxt("Ccmat2mxArray: Data has zero columns");
00908 for (c = 0; c < cols; c++) {
00909 for (r = 0; r < rows; r++) {
00910 *tempR++ = in_real[r][c];
00911 *tempI++ = in_imag[r][c];
00912 }
00913 }
00914 }
00915
00916 }
00917
00918 #endif // #ifndef ITMEX_H