Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual Studio C#-更改了文件目录,删除了.suo,现在某些功能无法工作_C#_Matlab_Visual Studio - Fatal编程技术网

Visual Studio C#-更改了文件目录,删除了.suo,现在某些功能无法工作

Visual Studio C#-更改了文件目录,删除了.suo,现在某些功能无法工作,c#,matlab,visual-studio,C#,Matlab,Visual Studio,我一直在编写一个函数来调用C#中的MATLAB函数。一切都很正常,直到我注意到,即使在更新了我的MATLAB函数之后,C#似乎仍在调用旧函数。所以我决定删除.suo文件,同时我也重新组织了我的文件夹结构 现在在我的C#中,我似乎无法调用其中一个C#函数来调用MATLAB代码。具体地说,我得到了一个错误: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in msco

我一直在编写一个函数来调用C#中的MATLAB函数。一切都很正常,直到我注意到,即使在更新了我的MATLAB函数之后,C#似乎仍在调用旧函数。所以我决定删除.suo文件,同时我也重新组织了我的文件夹结构

现在在我的C#中,我似乎无法调用其中一个C#函数来调用MATLAB代码。具体地说,我得到了一个错误:

    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

    Additional information: Error using cd

    Too many input arguments.
在这一行代码中:

        matlab.Feval("FFTAnalysis", 1, out result, fileNamesToAnalyzeText.Text, Convert.ToDouble(N));
有人知道问题是什么吗?这是C#

以及MATLAB代码:

function [frequency] = FFTAnalysis(fileName, N)
    close all
    N = double(N);

    % Change the current folder to the folder of this 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);

    for 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 for ';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 = '';
    for l = tStr
        if (length(find(special == l)) > 0)
            outStr = [outStr, '\', l];
        else
            outStr = [outStr, l];
        end
    end
end

错误消息中有一个提示:

其他信息:使用cd时出错

输入参数太多

如果您要
cd
到一个有空格的路径,您必须将该路径用引号括起来,否则它会认为您试图将单独的参数按空格分割传递给它

您可以使用“\”来转义引号(和其他字符),但现在您当然需要确保在路径中使用的“\”是有效的

试一试

您还需要对传递到matlab函数中的文件名执行相同的操作,它看起来是
filenametoanalyzetext.Text

function [frequency] = FFTAnalysis(fileName, N)
    close all
    N = double(N);

    % Change the current folder to the folder of this 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);

    for 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 for ';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 = '';
    for l = tStr
        if (length(find(special == l)) > 0)
            outStr = [outStr, '\', l];
        else
            outStr = [outStr, l];
        end
    end
end
matlab.Execute("cd \"c:\\Users\\Justin\\OneDrive\\Courses\\MECH 423\\Final Project\\8_MATLAB_FFTAnalysis\"");