You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void_printProperties(matvar_t *mat_var);
intmain()
{
Log::Init();
std::string filepath;
std::cout << "Please enter the path to your .mat file: ";
std::getline(std::cin, filepath);
mat_t *mat = Mat_Open(filepath.c_str(), MAT_ACC_RDONLY);
if (mat == nullptr) {
LOG_ERROR("Failed to open .mat file: {0}", filepath);
return1;
}
matvar_t *matVar = nullptr;
while ((matVar = Mat_VarReadNext(mat)) != nullptr) {
_printProperties(matVar);
if (matVar->data) {
unsigned size = matVar->nbytes / matVar->data_size;
if (matVar->data_type == MAT_T_DOUBLE) {
constdouble *data = static_cast<constdouble *>(matVar->data);
for (size_t i = 0; i < matVar->dims[0]; ++i) {
for (size_t j = 0; j < matVar->dims[1]; ++j) {
LOG_INFO("\t[{0}][{1}] = {2}", i, j, data[i + j * matVar->dims[0]]);
}
}
}
elseif (matVar->data_type == MAT_T_UTF8) {
constchar *data = static_cast<constchar *>(matVar->data);
LOG_INFO("Char: {0}", std::string(data, matVar->nbytes));
}
elseif (matVar->data_type == MAT_T_STRING) {
const std::string *data = static_cast<const std::string *>(matVar->data);
LOG_INFO("String: {0}", data->c_str());
}
}
else {
LOG_INFO("Data: (null)");
}
LOG_INFO("");
Mat_VarFree(matVar);
}
Mat_Close(mat);
return0;
}
std::string _getType(matio_types type)
{
switch (type) {
case MAT_T_UNKNOWN:
return"Unknown";
case MAT_T_INT8:
return"Int8";
case MAT_T_UINT8:
return"UInt8";
case MAT_T_INT16:
return"Int16";
case MAT_T_UINT16:
return"UInt16";
case MAT_T_INT32:
return"Int32";
case MAT_T_UINT32:
return"UInt32";
case MAT_T_SINGLE:
return"Single";
case MAT_T_DOUBLE:
return"Double";
case MAT_T_INT64:
return"Int64";
case MAT_T_UINT64:
return"UInt64";
case MAT_T_MATRIX:
return"Matrix";
case MAT_T_COMPRESSED:
return"Compressed";
case MAT_T_UTF8:
return"UTF8";
case MAT_T_UTF16:
return"UTF16";
case MAT_T_UTF32:
return"UTF32";
case MAT_T_STRING:
return"String";
case MAT_T_CELL:
return"Cell";
case MAT_T_STRUCT:
return"Struct";
case MAT_T_ARRAY:
return"Array";
case MAT_T_FUNCTION:
return"Function";
default:
return"Unknown Default";
}
}
void_printProperties(matvar_t *mat_var)
{
std::string msg;
std::string var_name = mat_var->name ? mat_var->name : "(unnamed)";
msg += fmt::format("---\nVariable: {0}, Type: {1}, Rank: {2}\n",
var_name,
_getType(mat_var->data_type),
mat_var->rank);
msg += fmt::format("Dimension: ");
for (int i = 0; i < mat_var->rank; ++i) {
msg += fmt::format("{0} x ", mat_var->dims[i]);
}
msg = msg.substr(0, msg.length() - 3); // Remove last " x "
msg += "\n";
LOG_INFO(msg);
}
When i feed in my .mat file
Note: the last variable str_last is actually char typed, it is named so to be placed at the last of the list, and used as an indicatior to show the list has come to the end.
As is shown, string data in .mat file are not recognized, as in the type is treated as MAT_T_UNKNOWN, and the weird thing is, if there's a string in the .mat file, there will be an extra Variable typed UInt8
The text was updated successfully, but these errors were encountered:
BruhGreg
changed the title
MAT_T_STRING not correctly recognized?MAT_T_STRING not correctly recognized?
Dec 10, 2024
I wrote a little snippet to parse
.mat
file:When i feed in my
.mat
fileThe output is as follows:
As is shown, string data in
.mat
file are not recognized, as in the type is treated asMAT_T_UNKNOWN
, and the weird thing is, if there's a string in the.mat
file, there will be an extra Variable typedUInt8
The text was updated successfully, but these errors were encountered: