How do I import an old .mat code, open the script and run it?

How do I import an old .mat code, open the script and run it? I am only able to import the variables but not the complete code!

2 Comments

That case you have to specify the errors.
The below is what I get when I tick off: ''Generate MATLAB code'' but what does this mean? I can see all the variables and constants but not the actual code...
function importfile(fileToRead1) %IMPORTFILE(FILETOREAD1) % Imports data from the specified file % FILETOREAD1: file to read
% Auto-generated by MATLAB on 21-Feb-2017 11:46:10
% Import the file newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields. vars = fieldnames(newData1); for i = 1:length(vars) assignin('base', vars{i}, newData1.(vars{i})); end

Sign in to comment.

Answers (2)

.mat files do not contain code AFAIK, so unless you saved code into something like an anonymous function, you cannot load code by loading a .mat file. You should look for .m files if you want code.
Okey, I think I understand but please confirm: if I only can find .mat-files, then this means I have actually lost these codes and I can never retrieve them again!?

1 Comment

Likely, but not definite. You might happen to have saved anonymous functions in the .mat . In the case of graphics objects, sometimes code is attached to the graphics objects -- though usually any substantial code would be in .m files instead of in graphics objects.

Sign in to comment.

Tags

No tags entered yet.

Asked:

on 21 Feb 2017

Commented:

on 21 Feb 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!