How to generate function after importing files

4 views (last 30 days)
Joël ESPEL
Joël ESPEL on 21 Feb 2017
Commented: Rik on 6 Mar 2017
Hello, I have student license of Matlab and after importing data I want to recreate what I just did and put it on one file to avoid doing it manually if I want to read multiple files. So I suppose that I need to "generate function". However, I can't do it interactively as I can with generate script. So can anybody please help me with this issue?
in tutorial
my version of matlab
Joël
  3 Comments
Joël ESPEL
Joël ESPEL on 5 Mar 2017
yes, you are right...the problem is that, in tutorials they can actually "generate function"
Which is not possible in my version of matlab
So, what can I do?
Rik
Rik on 6 Mar 2017
I have a student license as well. When check the 'generate script' box in the load interface (left click on .mat file), I get the following funtion:
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 06-Mar-2017 19:58:16
% 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
So I get a function. There is not much difference between a script and a function (mainly the variable scope), so I don't understand what part it is you want to automate/standardize.

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!