我在遍歷幾個if
語句超過8次時遇到了一些問題。該代碼似乎在前幾次比較中工作正常,執行算術運算並返回/保存輸出行'export_data'
。但是,在此之後,它僅返回else
條件和響應。被評估的變量每個都有1500行。我已經添加了下面的代碼和兩張顯示輸出的照片。任何洞察力將非常感激。Matlab不解決if語句
function [export_data] = WS_Zones(Forecast_WS, Observed_WS)
if (Forecast_WS > Observed_WS)
WS_Zone_1 = Observed_WS.*1.24;
WS_Zone_2 = Observed_WS.*1.28;
elseif (Forecast_WS < Observed_WS)
WS_Zone_1 = Observed_WS.*0.76;
WS_Zone_2 = Observed_WS.*0.72;
else
WS_Zone_1 = Observed_WS;
WS_Zone_2 = Observed_WS;
end
export_data=[Forecast_WS Observed_WS WS_Zone_1 WS_Zone_2];
filename = 'testdata.xlsx';
sheet = 1;
xlRange = 'A1';
xlswrite(filename,export_data,sheet,xlRange)
end
Matlab軟件行爲罰款。我建議你閱讀[if](http://www.mathworks.com/help/matlab/ref/if.html?requestedDomain=www.mathworks.com)文檔,特別是「比較陣列」和「測試陣列爲平等「。 –
如果'Forecast_WS'和'Observed_WS'不是標量,'如果Forecast_WS> Observed_WS'只取決於每個元素中第一個元素的比較。 – horchler