Function syntax / execution

조회 수: 2 (최근 30일)
nathan stallworth
nathan stallworth 2021년 8월 16일
댓글: nathan stallworth 2021년 8월 17일
I am attempting to write this function and if I just run it the output is correct, however if i set the inputs in the command line to something else and then run it the same answer is provdied (pretty much ignored the input values in the command line and took the input from the input files). I am not very experienced with function wiriting so this will probably a rather trivial mistake.
Thank you
  댓글 수: 2
Stephen23
Stephen23 2021년 8월 17일
"pretty much ignored the input values in the command line and took the input from the input files"
Note that the MATLAB Editor highlighted and underlined the two input arguments, telling you that they are unused:
When the Editor underlines something, you should pay attention to that message.
nathan stallworth
nathan stallworth 2021년 8월 17일
Understood, since they were used later on in the code I didn't understand why it said "unsued".
Thank you

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

답변 (1개)

dpb
dpb 2021년 8월 17일
" (pretty much ignored the input values in the command line and took the input from the input files)"
No "pretty much" about it -- there's no point in having the input arguments as you wrote the function; you hardcoded the file names into the function and read them into the two variables in the argument list, thereby overwriting them.
If the point is to read different sets of files and so the same thing on them, then pass the two file names to the function instead.
  댓글 수: 6
Steven Lord
Steven Lord 2021년 8월 17일
In that case your function should start with:
function [output] = binning_Func(file1, file2)
data_input = importdata(file1, ' ',1);
% Snip the rest of the function
When you call your function to test it define your actual data file names and pass them into your function.
file1 = 'C:\Users\NSTALLWORTH\Documents\Aegis\21 - end of FY Wrap\Output Data_og.xlsx';
file2 = 'C:\Users\NSTALLWORTH\Documents\Aegis\21 - end of FY Wrap\phandoff_altitude_bins.xlsx';
output = binning_Func(file1, file2);
When you call your function "for real" define file1 and file2 to contain the names of your real data files and then call binning_Func as before.
nathan stallworth
nathan stallworth 2021년 8월 17일
Okay this has been a great learning experience, I appreciate it!

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

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by