Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121626630
mexexpand.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 12, 14:43
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Jul 14, 14:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27355063
Attached To
R1252 EMPoWER
mexexpand.c
View Options
/***********************************************************************
* mexexpand.c : C mex file
*
* z = mexexpand(blk,x);
*
* Input: blk = [n1, n2, ..., nk]
*
* Output: [x1 x1...x1, x2 x2...x2, ...., xk xk...xk]'
* n1 n2 nk
*
* SDPT3: version 3.0
* Copyright (c) 1997 by
* K.C. Toh, M.J. Todd, R.H. Tutuncu
* Last Modified: 2 Feb 01
***********************************************************************/
#include <mex.h>
#include <math.h>
#if !defined(MAX)
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#endif
/**********************************************************
*
***********************************************************/
void
mexFunction
(
int
nlhs
,
mxArray
*
plhs
[],
int
nrhs
,
const
mxArray
*
prhs
[]
)
{
double
*
blksize
,
*
x
,
*
z
;
int
k
,
l
,
blkdim
,
numblk
,
cols
,
idx
;
/* CHECK FOR PROPER NUMBER OF ARGUMENTS */
if
(
nrhs
!=
2
){
mexErrMsgTxt
(
"mexexpand: requires 2 input arguments."
);
}
if
(
nlhs
>
1
){
mexErrMsgTxt
(
"mexexpand: requires 1 output argument."
);
}
/* CHECK THE DIMENSIONS */
numblk
=
MAX
(
mxGetM
(
prhs
[
0
]),
mxGetN
(
prhs
[
0
]));
blksize
=
mxGetPr
(
prhs
[
0
]);
cols
=
0
;
for
(
k
=
0
;
k
<
numblk
;
k
++
)
{
cols
=
cols
+
(
int
)
blksize
[
k
];
}
x
=
mxGetPr
(
prhs
[
1
]);
if
(
mxIsSparse
(
prhs
[
1
]))
{
mexErrMsgTxt
(
"mexexpand: sparse x not allowed"
);
}
if
(
MAX
(
mxGetM
(
prhs
[
1
]),
mxGetN
(
prhs
[
1
]))
!=
numblk
)
{
mexErrMsgTxt
(
"mexexpand: size of blk and x incompatible."
);
}
plhs
[
0
]
=
mxCreateDoubleMatrix
(
cols
,
1
,
mxREAL
);
z
=
mxGetPr
(
plhs
[
0
]);
idx
=
0
;
for
(
k
=
0
;
k
<
numblk
;
k
++
)
{
blkdim
=
(
int
)
blksize
[
k
];
for
(
l
=
0
;
l
<
blkdim
;
l
++
)
{
z
[
idx
]
=
x
[
k
];
idx
++
;
}
}
return
;
}
/**********************************************************/
Event Timeline
Log In to Comment