Why doesn't my function for writing a file work?

1 visualización (últimos 30 días)
Allen Hammack
Allen Hammack el 15 de Oct. de 2021
Comentada: Allen Hammack el 15 de Oct. de 2021
I have a section of code that I'm trying to convert to a function. This code works without being used as a function, so the problem is seemingly with how I'm defining the function. MHere is my function:
function write_fill_empty_data_model_temp(input_general,...
data_proc_fill_empty)
output_file_fill_empty_data_model = fopen(strcat(pwd,'\',...
input_general{1}.raw_data_daily_directory,'\',...
input_general{1}.raw_data_test_directory,'\',...
input_general{1}.fill_empty_file_name,...
'_fill_empty_data_model.txt'),'w');
fprintf(output_file_fill_empty_data_model,'%s\t%s\n',...
'Time - Model (s)',...
'Valve 1 Position (%)');
fprintf(output_file_fill_empty_data_model,'%.3f\t%.3f\n',...
[data_proc_fill_empty{1}.time_model_no_shift,...
data_proc_fill_empty{1}.valve_1_opening_percent]');
fclose(output_file_fill_empty_data_model);
end
My inputs are two structures. As best as I can tell, the only inputs to this function are the two structures. When I call this function, I get this error:
Not enough input arguments.
Error in write_fill_empty_data_model (line 3)
output_file_fill_empty_data_model =
fopen(strcat(pwd,'\',input_general{1}.raw_data_daily_directory,'\',input_general{1}.raw_data_test_directory,'\',input_general{1}.fill_empty_file_name,'_fill_empty_data_model.txt'),'w');
I have struggled to figure out the problem. Can someone please help?

Respuesta aceptada

Jan
Jan el 15 de Oct. de 2021
Editada: Jan el 15 de Oct. de 2021
"Not enough input arguments" might mean, that you call this function without inputs. Therefore the most important part of the code is missing: how do you call this function?
Maybe you press the green triangle in the editor? This would call trhe function without inputs.
Remarks:
Try to find simpler names for functions and variables. "write_fill_empty_data_model_temp", "input_general" and "data_proc_fill_empty" look really confusing. Calling a file ID "output_file_fill_empty_data_model" is very strange. The standard "fid" is a nice convention.
fullfile() is smarter than strcat() to concatenate path names.
  1 comentario
Allen Hammack
Allen Hammack el 15 de Oct. de 2021
You were right! I wasn't including the inputs for this funciton in my main script. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by