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
Walter Roberson 2017년 11월 18일
MATLAB is case sensitive. inputA is not the same as InputA
Matheus
Matheus 2017년 11월 18일
편집: Matheus 2017년 11월 18일
This is not the problem. In my code, I checked if I was consistent with the variable names.
clear all
clears all variables. At the start of any function it is totally counter-productive cargo-cult programing:
Matheus
Matheus 2017년 11월 18일
Thank you. It worked!

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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.

댓글 수: 1

Matheus
Matheus 2017년 11월 18일
I deleted "clear all", now it works. Thank you.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

질문:

2017년 11월 18일

댓글:

2017년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by