How can I run two functions in one script file?

I have:
function [data]=input(user_defined_data)
%code that put the inputs in a cell array
end
function [output]=new_function_in_same_mfile(data)
%this should read the data array from the above function so I can do some calculations with it.
end
My problem is that MATLAB will run the first function but not the second. I have tried putting a readinput in between the functions, but MATLAB counts this as an error. I thought I needed a global variable, but when I tried to make data global, it won't accept data as global. How do I make the second function use the output from the first as an input, and run, in the same script file?

 채택된 답변

Steven Lord
Steven Lord 2016년 10월 16일

0 개 추천

I would avoid calling your first function input as there's already a function by that name in MATLAB.
Only the first function in a file is visible / callable to functions outside that file. So create a new main (first) function in your file and have that main function call both your local functions. In the terminology of that example, the input and new_function_in_same_mfile functions would play the roles of mymean and mymedian, while the new main function would play the role of mystats.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2016년 10월 16일

댓글:

2016년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by