Using a text file as a function parameter

6 Ansichten (letzte 30 Tage)
Matheus
Matheus am 18 Nov. 2017
Kommentiert: Matheus am 18 Nov. 2017
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 Kommentare
Stephen23
Stephen23 am 18 Nov. 2017
clear all
clears all variables. At the start of any function it is totally counter-productive cargo-cult programing:
Matheus
Matheus am 18 Nov. 2017
Thank you. It worked!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 18 Nov. 2017
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 Kommentar
Matheus
Matheus am 18 Nov. 2017
I deleted "clear all", now it works. Thank you.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by