How to pass a string as an argument to a function in MATLAB?

Basically, I have 10 data files, and I wrote a MATLAB function to process this data. The code looks like this:

function Z = fitdata(file_path)

  A = importdata(file_path,',');
  ...

end

Since I do not want to enter the same command 10 times (for different file names), I wrote another script to automate this processing. The code is as follows:

function X = automate()

  myarray = {'file_one', 'file_two', 'file_three',......,'file_ten'};
  for i = 1:9
    mypath = myarray{i};
    W = fitdata(mypath);
    ...
  end

end

But I get the error "Too many input arguments" when calling the function fitdata (file_path).

How can I do it?

+5
source share
1 answer

:. , , , , , , , fitdata, , MATLAB. , script fitdata.m, , .


:

, IMPORTDATA IMPORT, , .

: path, PATH. ( MATLAB), , , .

+4

All Articles