Trouble with declaring function output

조회 수: 1 (최근 30일)
Chris Moon
Chris Moon 2019년 6월 27일
댓글: Chris Moon 2019년 6월 28일
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 = temp.data(:,4);
radAvg = mean(radData(~radData==0));
data{i} = radAvg;
end
end
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
...
end
data
end
shows that my code works otherwise. I am not sure what I did wrong but any help would be greatly appreciated.

채택된 답변

James Tursa
James Tursa 2019년 6월 27일
function data = importer
  댓글 수: 1
Chris Moon
Chris Moon 2019년 6월 28일
wow I'm dumb, can't believe I forgot the order. Thanks alot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by