最后一个elseif语句不执行

时间:2015-05-26 11:04:42

标签: matlab if-statement

即使满足条件,我的最后一个elseif语句也不会执行:

Currency_Exchanage!='选择...'和所有其他变量(ETF_Exchanage,Index_Exchanage和Stock_Exchanage)='选择......'

以下是我关注的代码部分:

if (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
        (strcmp(Currency_Exchanage,'Select...') == 1)
    if db == 1 && uni == 1
        tickers = gnr_bloomberg; % Analsise Bloomberg natural resources
        nrm=1;
    elseif db == 1 && uni == 2
        tickers = all_bloomberg; % Analsise Bloomberg all
        nrm=1;
    elseif db == 2 && uni == 1
        tickers = gnr_yahoo;     % Analsise Yahoo natural resources
        nrm=1;
    elseif db == 2 && uni == 2
        tickers = all_yahoo;     % Analsise Yahoo all
        nrm=1;
    end
else
    %Yahoo inputs
    if (strcmp(ETF_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
            (strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from ETF
        tickers = ETF_Yahoo(:,1);
        Exchanges = ETF_Yahoo(:,2);
        Exchange = ETF_Exchanage;
        db=2; %Yahoo Selection

    elseif (strcmp(Index_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(ETF_Exchanage,'Select...') == 1)...
            (strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Index
        tickers = Index_Yahoo(:,1);
        Exchanges = Index_Yahoo(:,2);
        Exchange = Index_Exchanage;
        db=2;

    elseif (strcmp(Stock_Exchanage,'Select...') == 0) && (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
            (strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Stock
        tickers = Stock_Yahoo(:,1);
        Exchanges = Stock_Yahoo(:,2);
        Exchange = Stock_Exchanage;
        db=2;

    elseif (strcmp(Currency_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
            (strcmp(ETF_Exchanage,'Select...') == 1); %Choose exhanges from Currency
        tickers = Currency_Yahoo(:,1);
        Exchanges = Currency_Yahoo(:,2);
        Exchange = Currency_Exchanage;
        db=2;
    else
        msg = 'Error occurred.\Only one Yahoo input menue must be used!';
        error(msg)
    end
end

任何帮助都会被挪用,我​​无法看到我在这里出错的地方。我正在使用Matlab 2013a。

1 个答案:

答案 0 :(得分:1)

在有问题的elseif语句中放置断点,然后在命令窗口中检查条件评估的内容。

如果评估不符合预期,请检查各个术语的评估结果。

在matlab中实际测试条件评估的内容非常重要,而不是仅仅在视觉上比较字符串值。

通常到那时你应该大致了解出了什么问题。

但是在您的情况下,我们无法为您执行这些步骤,因为某些内容已关闭。您的代码浓缩为更合理的最小示例

if 1 && 1 && 1...
    1;
    disp('I was here')
end

甚至没有在R2014a中执行,因为解释器抱怨'...'是一个意想不到的matlab表达式。