matrix dimension must agree

谁说胖子不能爱 提交于 2020-01-06 15:17:28

问题


My dropdown list contains the ff. strings: Low Pass, High Pass, Band Pass, Stop Band. Whenever I choose the Low Pass, the error below shows. The code below works for the rest.

My goal is to make the edtCutoff2 and txtRange invisible when I choose Low Pass and High Pass but the code below works only for High Pass.

Error:

Error using  == 
Matrix dimensions must agree.

Error in untitled>popFreqResp_Callback (line 168)
if ((str == 'Stop Band') | (str == 'Band Pass') == 1)

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in untitled (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in@(hObject,eventdata)untitled('popFreqResp_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

Code Snippet

function popFreqResp_Callback(hObject, eventdata, handles)
list=get(handles.popFreqResp,'String');
str=list{get(handles.popFreqResp,'Value')};
if ((str == 'Stop Band') | (str == 'Band Pass') == 1)
    set(handles.edtCutoff2,'Visible','on');
    set(handles.txtRange,'Visible','on');
else
    set(handles.edtCutoff2,'Visible','off');
    set(handles.txtRange,'Visible','off');
end

回答1:


You shouldn't compare strings using '==', because it will throw the error you see if the strings are not the same length. Essentially '==' is comparing two matrices of type char - if they don't have the same length, '==' isn't defined. Since 'Low Pass' has a length of 8, and 'Band Pass' has a length of 9, you can't compare them in this manner.

Use strcmp instead. Or strcmpi if you don't care about case.



来源:https://stackoverflow.com/questions/20109738/matrix-dimension-must-agree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!