1

I have a huge bunch of data where ne is a variable. When I load it into MATLAB 2013b, and try to use it, I get

Error using ne.
Not enough input arguments.

Changing all the ne to some other name would be laborious. Any hacks?

This is a short code snippet:

function test(lambda, range)
% lambda is a number, range is a vector passed like 1:10 %

    for i = range
        load ('data.mat');    % data.mat contains a variable called 'ne' among others. %
        T = exp(-ne);

    ...

When calling the function, there's the error saying that ne has not been provided with enough input args.

Shai
  • 111,146
  • 38
  • 238
  • 371
user2354033
  • 45
  • 1
  • 6

2 Answers2

1

You need to tell matlab ne is a variable BEFORE you load it:

ne = []; % this will tell matlab ne is a variable
for ii = range
     load('data.mat'); % loading ne
     T = exp(-ne); % should work just fine now...

PS,
It is best not to use i as a variable name in Matlab.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • @user2354033 - glad I could help. If this solution worked for you, please consider "accepting" it by clicking the "V" icon beside it. – Shai Feb 20 '14 at 06:25
1

Another (better?) way is to avoid loading 'data.mat' directly into the global workspace. If you write:

testData = load('data.mat');

then your variable will be testData.ne, which does not clash with the built-in ne. This technique also avoids accidentally overwriting variables in your workspace which happen to have the same name as a variable in the .mat file.

Max
  • 2,121
  • 3
  • 16
  • 20