MATLAB Answers

Trouble with declaring function output

1 view (last 30 days)
Chris Moon
Chris Moon on 27 Jun 2019
Commented: Chris Moon on 28 Jun 2019
I created a function for importing data from text files, and then outputting an array of the averages of these data.
data = function importer
files = dir('*.txt');
for i = 1:length(files)
temp = importdata(files(i).name);
radData =,4);
radAvg = mean(radData(~radData==0));
data{i} = radAvg;
When I run the code however, I get the error
Error: File: importer.m Line: 1 Column: 8
Function definitions are not permitted in this context.
However, defining the function simply as
function importer
and then displaying the final array at the end of the code
shows that my code works otherwise. I am not sure what I did wrong but any help would be greatly appreciated.


Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 27 Jun 2019
function data = importer

  1 Comment

Chris Moon
Chris Moon on 28 Jun 2019
wow I'm dumb, can't believe I forgot the order. Thanks alot!

Sign in to comment.

More Answers (0)