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 个评论

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

请先登录,再进行评论。

回答(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 个评论

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.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by