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

2 ビュー (過去 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 Center および File ExchangeStructures についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by