1
votes

I am trying to load a .mat file using the 'load' function. The file seems to load correctly, but some of the variables are not accessible. My best guess is that this is because the name of the variables (which was set by someone else in R and then exported to a .mat file) contains a dot (see pic)

enter image description here

As an example, one of the variables is a vector called 'final.product'. If I try to access the first element, I would get this

>>final.product(1)
Undefined variable "final" or class "final.product".

This works fine with the variables whose name do not contain any dots.

I have tried to modify the name from the Workspace (i.e. by clicking once on the name and removing the dot), but I am prompted with an error message saying

enter image description here

All the other things I have tried in the Command Window give me errors related to the fact that my variables don't exist or that the name is invalid, for example

>> T = from.product;
Undefined variable "from" or class "from.product".

Or

>>T = load('C:\Users\Loup\Downloads\5. Source-Intermediates-Products.mat', 'final.product');
T = T.('final.product');
Error using load
Invalid field name: 'final.product'.

So I guess I have two questions:

1) can someone confirm that my issue is caused by having dots in the variable names?

2) is there a way to rename a variable that does not require being able to read them?

Thanks a lot!

1
@ 1) Matlab thinks it is a class/object or structure if it has a dot inside. So yes, this can be confirmed. - avermaet
It's not clear to me how it would be possible to even load a variable with a dot in the name... this is a rare occasion where a screenshot of your workspace showing the erroneous variables would be beneficial (please edit your question). - Wolfie
@Wolfie agree, thanks for the suggestion (added pics now) - user3387439
These are indeed not valid variable names. I would suggest loading the MAT-file in R, and creating a new one with valid variable names. - Cris Luengo
Thanks @CrisLuengo, that's what I ended up doing although I really didn't want to have to deal with R... - user3387439

1 Answers

0
votes

I did not manage to find a good answer to what I wanted to do. In case someone has the same issue, I ended up having to get the file in R and change the name there.

Cheers