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

1 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2021-10-15
编辑:Jan 2021-10-15
"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 个评论
Allen Hammack
Allen Hammack 2021-10-15
You were right! I wasn't including the inputs for this funciton in my main script. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by