89 const QStringList& pickcollist,
95 if (!pickrowlist.isEmpty() && this->rowlist.isEmpty()) {
96 qCritical(
"MNENamedMatrix::pick - Cannot pick rows: no row names in original matrix.");
99 if (!pickcollist.isEmpty() && this->collist.isEmpty()) {
100 qCritical(
"MNENamedMatrix::pick - Cannot pick columns: no column names in original matrix.");
107 if (pickrowlist.isEmpty())
108 picknrow = this->
nrow;
109 if (pickcollist.isEmpty())
110 pickncol = this->
ncol;
115 Eigen::VectorXi pick_row = Eigen::VectorXi::Zero(picknrow);
116 QStringList my_pickrowlist;
118 if (!pickrowlist.isEmpty()) {
119 for (
int j = 0; j < picknrow; ++j) {
120 const QString& name = pickrowlist[j];
122 for (
int k = 0; k < this->
nrow; ++k) {
123 if (QString::compare(name, this->
rowlist[k]) == 0) {
128 if (pick_row[j] == -1) {
129 qCritical(
"MNENamedMatrix::pick - Row '%s' not found in original matrix.",
130 name.toUtf8().constData());
134 my_pickrowlist = pickrowlist;
136 for (
int k = 0; k < picknrow; ++k)
138 my_pickrowlist = this->
rowlist;
144 Eigen::VectorXi pick_col = Eigen::VectorXi::Zero(pickncol);
145 QStringList my_pickcollist;
147 if (!pickcollist.isEmpty()) {
148 for (
int j = 0; j < pickncol; ++j) {
149 const QString& name = pickcollist[j];
151 for (
int k = 0; k < this->
ncol; ++k) {
152 if (QString::compare(name, this->
collist[k]) == 0) {
157 if (pick_col[j] == -1) {
158 qCritical(
"MNENamedMatrix::pick - Column '%s' not found in original matrix.",
159 name.toUtf8().constData());
163 my_pickcollist = pickcollist;
165 for (
int k = 0; k < pickncol; ++k)
167 my_pickcollist = this->
collist;
173 Eigen::MatrixXf pickdata(picknrow, pickncol);
174 for (
int j = 0; j < picknrow; ++j) {
175 const int row = pick_row[j];
176 for (
int k = 0; k < pickncol; ++k)
177 pickdata(j, k) = this->
data(row, pick_col[k]);
180 return build(picknrow, pickncol, my_pickrowlist, my_pickcollist, pickdata);
189 QStringList colnames;
190 QStringList rownames;
194 QVector<qint32> dims;
197 bool dataFound =
false;
206 if (!tmp_node->find_tag(stream, kind, t_pTag))
209 t_pTag->getMatrixDimensions(ndim, dims);
211 qCritical(
"MNENamedMatrix::read - Only two-dimensional matrices are supported.");
215 data = t_pTag->toFloatMatrix().transpose();
218 for (
int k = 0; k < tmp_node->nchild(); ++k) {
220 if (tmp_node->children[k]->find_tag(stream, kind, t_pTag)) {
221 t_pTag->getMatrixDimensions(ndim, dims);
223 qCritical(
"MNENamedMatrix::read - Only two-dimensional matrices are supported.");
227 data = t_pTag->toFloatMatrix().transpose();
229 tmp_node = tmp_node->children[k];
245 nrow = *t_pTag->toInt();
246 if (
nrow != dims[0]) {
247 qCritical(
"MNENamedMatrix::read - FIFF_MNE_NROW tag (%d) conflicts with matrix data (%d).",
256 ncol = *t_pTag->toInt();
257 if (
ncol != dims[1]) {
258 qCritical(
"MNENamedMatrix::read - FIFF_MNE_NCOL tag (%d) conflicts with matrix data (%d).",
268 const QString s = t_pTag->toString();
270 if (rownames.size() !=
nrow) {
271 qCritical(
"MNENamedMatrix::read - Row name count (%d) does not match nrow (%d).",
272 static_cast<int>(rownames.size()),
nrow);
278 const QString s = t_pTag->toString();
280 if (colnames.size() !=
ncol) {
281 qCritical(
"MNENamedMatrix::read - Column name count (%d) does not match ncol (%d).",
282 static_cast<int>(colnames.size()),
ncol);
static std::unique_ptr< MNENamedMatrix > read(QSharedPointer< FIFFLIB::FiffStream > &stream, const QSharedPointer< FIFFLIB::FiffDirNode > &node, int kind)
Factory: read a named matrix from a FIFF file.
static std::unique_ptr< MNENamedMatrix > build(int nrow, int ncol, const QStringList &rowlist, const QStringList &collist, const Eigen::MatrixXf &data)
Factory: build a named matrix from its constituent parts.
std::unique_ptr< MNENamedMatrix > pick(const QStringList &pickrowlist, int picknrow, const QStringList &pickcollist, int pickncol) const
Create a sub-matrix by picking named rows and columns.