Function syntax / execution

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 comentarios

Stephen23
Stephen23 el 17 de Ag. de 2021
"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 el 17 de Ag. de 2021
Understood, since they were used later on in the code I didn't understand why it said "unsued".
Thank you

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 17 de Ag. de 2021

1 voto

" (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 comentarios

dpb
dpb el 17 de Ag. de 2021
BTW, I would have edited your function if you had pasted it as code instead of as an image -- but it's too much work to have to type it all in again...
nathan stallworth
nathan stallworth el 17 de Ag. de 2021
Hey there, I get what you're saying however I am still confused how to exactly use the inputs then. I do apolgize about not posting the actualy code, i will post it here if you still willing to assist. Thank you
function [output] = binning_Func(in1,in2)
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';
data_input = importdata(file1, ' ',1);
data = data_input.data(:,:);
alt_input = importdata(file2, ' ',1);
binning = alt_input.data(:,:);
altitude = data(:,9);
eci = data(:,3:8);
sat_ID = data(:,1);
info = cell(length(altitude),10);
for i = 1:length(binning)
ind = find((altitude >= binning(i,2)) & (altitude < binning(i,3)));
binVal = i-1;
binMat = zeros(length(ind),1);
binMat(:,:) = binVal;
output = [sat_ID(ind,1) eci(ind,1) eci(ind,2) eci(ind,3) eci(ind,4) eci(ind,5) eci(ind,6) altitude(ind,1) binMat];
info{i} = (output);
t = vertcat(info{:});
table = array2table(t,'VariableNames',{'satID','X (km)', 'Y (km)', 'Z (km)', 'XDot (km/s)', 'YDot (km/s)', 'ZDot (km/s)', 'Altitude (km)', 'Bin Ind'});
end
output = table;
writetable(table,'Output Data Full.txt','Delimiter','\t');
type 'Output Data Full.txt';
filename = 'Output Data Full.xlsx';
sheets = 1;
writetable(table, filename, 'Sheet',sheets, 'Range', 'A1');
end
Walter Roberson
Walter Roberson el 17 de Ag. de 2021
Do you want the user to pass in file names or pass in the actual data?
nathan stallworth
nathan stallworth el 17 de Ag. de 2021
File name, but i wanted to test it using actual data.
Steven Lord
Steven Lord el 17 de Ag. de 2021
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 el 17 de Ag. de 2021
Okay this has been a great learning experience, I appreciate it!

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 16 de Ag. de 2021

Comentada:

el 17 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by