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

조회 수: 1 (최근 30일)
Allen Hammack
Allen Hammack 2021년 10월 15일
댓글: Allen Hammack 2021년 10월 15일
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