108 const QStringList& pickcollist,
114 if (!pickrowlist.isEmpty() && this->rowlist.isEmpty()) {
115 qCritical(
"MNENamedMatrix::pick - Cannot pick rows: no row names in original matrix.");
118 if (!pickcollist.isEmpty() && this->collist.isEmpty()) {
119 qCritical(
"MNENamedMatrix::pick - Cannot pick columns: no column names in original matrix.");
126 if (pickrowlist.isEmpty())
127 picknrow = this->
nrow;
128 if (pickcollist.isEmpty())
129 pickncol = this->
ncol;
134 std::vector<int> pick_row(picknrow);
135 QStringList my_pickrowlist;
137 if (!pickrowlist.isEmpty()) {
138 for (
int j = 0; j < picknrow; ++j) {
139 const QString& name = pickrowlist[j];
141 for (
int k = 0; k < this->
nrow; ++k) {
142 if (QString::compare(name, this->
rowlist[k]) == 0) {
147 if (pick_row[j] == -1) {
148 qCritical(
"MNENamedMatrix::pick - Row '%s' not found in original matrix.",
149 name.toUtf8().constData());
153 my_pickrowlist = pickrowlist;
155 for (
int k = 0; k < picknrow; ++k)
157 my_pickrowlist = this->
rowlist;
163 std::vector<int> pick_col(pickncol);
164 QStringList my_pickcollist;
166 if (!pickcollist.isEmpty()) {
167 for (
int j = 0; j < pickncol; ++j) {
168 const QString& name = pickcollist[j];
170 for (
int k = 0; k < this->
ncol; ++k) {
171 if (QString::compare(name, this->
collist[k]) == 0) {
176 if (pick_col[j] == -1) {
177 qCritical(
"MNENamedMatrix::pick - Column '%s' not found in original matrix.",
178 name.toUtf8().constData());
182 my_pickcollist = pickcollist;
184 for (
int k = 0; k < pickncol; ++k)
186 my_pickcollist = this->
collist;
192 Eigen::MatrixXf pickdata(picknrow, pickncol);
193 for (
int j = 0; j < picknrow; ++j) {
194 const int row = pick_row[j];
195 for (
int k = 0; k < pickncol; ++k)
196 pickdata(j, k) = this->
data(row, pick_col[k]);
199 return build(picknrow, pickncol, my_pickrowlist, my_pickcollist, pickdata);
208 QStringList colnames;
209 QStringList rownames;
213 QVector<qint32> dims;
216 bool dataFound =
false;
225 if (!tmp_node->find_tag(stream, kind, t_pTag))
228 t_pTag->getMatrixDimensions(ndim, dims);
230 qCritical(
"MNENamedMatrix::read - Only two-dimensional matrices are supported.");
234 data = t_pTag->toFloatMatrix().transpose();
237 for (
int k = 0; k < tmp_node->nchild(); ++k) {
239 if (tmp_node->children[k]->find_tag(stream, kind, t_pTag)) {
240 t_pTag->getMatrixDimensions(ndim, dims);
242 qCritical(
"MNENamedMatrix::read - Only two-dimensional matrices are supported.");
246 data = t_pTag->toFloatMatrix().transpose();
248 tmp_node = tmp_node->children[k];
264 nrow = *t_pTag->toInt();
265 if (
nrow != dims[0]) {
266 qCritical(
"MNENamedMatrix::read - FIFF_MNE_NROW tag (%d) conflicts with matrix data (%d).",
275 ncol = *t_pTag->toInt();
276 if (
ncol != dims[1]) {
277 qCritical(
"MNENamedMatrix::read - FIFF_MNE_NCOL tag (%d) conflicts with matrix data (%d).",
287 const QString s = t_pTag->toString();
289 if (rownames.size() !=
nrow) {
290 qCritical(
"MNENamedMatrix::read - Row name count (%d) does not match nrow (%d).",
291 static_cast<int>(rownames.size()),
nrow);
297 const QString s = t_pTag->toString();
299 if (colnames.size() !=
ncol) {
300 qCritical(
"MNENamedMatrix::read - Column name count (%d) does not match ncol (%d).",
301 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.