matlab - Visual Studios C# - Changed file directories, deleted .suo and now certain functions do not work -


i have been coding function interface call matlab functions in c#. working fine until noticed after updating matlab functions, c# seemed calling old functions. decide delete .suo file , in mean time reorganized folder structure.

now in c#, cannot seem call 1 of c# functions call matlab code. getting error:

    unhandled exception of type 'system.runtime.interopservices.comexception' occurred in mscorlib.dll      additional information: error using cd      many input arguments. 

on line of code:

        matlab.feval("fftanalysis", 1, out result, filenamestoanalyzetext.text, convert.todouble(n)); 

does know issue is? here c#

private void matlabfft_click(object sender, eventargs e) {     int n = convert.toint32(numberoffilestext.text);      // create matlab instance      mlapp.mlapp matlab = new mlapp.mlapp();      // change directory function located      matlab.execute(@"cd c:\users\justin\onedrive\courses\mech 423\final project\8_matlab_fftanalysis");      // define output      object result = null;      // call matlab function myfunc     //matlab.feval("fftanalysis", 2, out result, filenamestoanalyzetext.text, convert.todouble(n));     matlab.feval("fftanalysis", 1, out result, filenamestoanalyzetext.text, convert.todouble(n));      // quit matlab } 

and matlab code:

function [frequency] = fftanalysis(filename, n)     close     n = double(n);      % change current folder folder of m-file.     % courtesy of brett shoelson     if(~isdeployed)       cd(fileparts(which(mfilename)));     end     dir = 'c:\users\justin\onedrive\courses\mech 423\final project\5_c_sharp_egg_test_data_logger\data_log_files\';      fs = 111.9;           % sampling frequency     t = 1/fs;      data = cell(1,n);      i=1:n;     %     filename = 'data_3min_3_';         postfix = '.txt';         fullfilename = strcat({dir},{'\'},{filename},{int2str(i)},{postfix});         data{i} = load(fullfilename{1});          average = mean(data{i});         indices = find(abs(data{i})>1000);         data{i}(indices) = average;          [b,a] = butter(4,[5/(fs/2) 12/(fs/2)]);         data{i} = filtfilt(b,a,data{i});          l = length(data{i});          y = fft(data{i});         p2 = abs(y/l);         p1 = p2(1:l/2+1);         p1(1) = 0;         p1(2:end-1) = 2*p1(2:end-1);         f = fs*(0:(l/2))/l;         t = (0:l-1)*t;        % time vector          [m,n] = max(p1);         frequency = n*(fs/l);          subplot(2,n,i);         plot(t,data{i});         textfile = strcat({appendbackslash(filename)},{int2str(i)},{postfix});         title({'raw signal ';textfile{1}});          subplot(2,n,i+n);         plot(f,p1);         peakfreq = strcat({'egg frequency: '},{num2str(frequency)});         title({'frequency histogram';num2str(frequency)});     end end  function [outstr] = appendbackslash(tstr)      special = '_';      outstr = '';     l = tstr         if (length(find(special == l)) > 0)             outstr = [outstr, '\', l];         else             outstr = [outstr, l];         end     end end 

there hint in error message:

additional information: error using cd

too many input arguments.

if you're going cd path has spaces, have wrap path in quotes, or else thinks you're trying pass separate arguments split on spaces.

you can escape quotes (and other characters) using "\", of course need make sure "\" use in path valid.

try

matlab.execute("cd \"c:\\users\\justin\\onedrive\\courses\\mech 423\\final project\\8_matlab_fftanalysis\""); 

you'll need same filename pass matlab function, looks that's filenamestoanalyzetext.text.


Comments