Using a text file as a function parameter
显示 更早的评论
I am trying to create a function where the inputs are text files. For some reason, the program is not reading the files, I am getting the message "Reference to a cleared variable input A".
function [result] = funtion_name(InputA,InputB,InputC);
clear all
VariableA= dlmread(InputA);
VariableB= dlmread(InputB);
VariableC=fileread(InputC);
%Do something
end
4 个评论
Walter Roberson
2017-11-18
MATLAB is case sensitive. inputA is not the same as InputA
Stephen23
2017-11-18
clear all
clears all variables. At the start of any function it is totally counter-productive cargo-cult programing:
Matheus
2017-11-18
回答(1 个)
Walter Roberson
2017-11-18
0 个投票
The "clear all" is clearing the input parameters.
You should never use "clear all" inside a function. If you use it at all inside a script, it should be reserved for a script that does nothing but reset the state of MATLAB, to be used only under circumstances where you might otherwise close MATLAB and restart it.
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!