矩阵维度必须一致 [英] matrix dimension must agree

查看:939
本文介绍了矩阵维度必须一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下拉列表包含了ff。字符串:低通,高通,带通,阻带。每当我选择低通,下面的错误显示。下面的代码适用于其他的。



我的目标是在选择低通和高通时使edtCutoff2和txtRange不可见,但下面的代码仅适用于高通

错误:

 错误使用== 
矩阵尺寸必须一致。

在无标题> popFreqResp_Callback(第168行)中出错
if((str =='Stop Band')|(str =='Band Pass')== 1)

gui_mainfcn错误(第96行)
feval(varargin {:});

无标题(第42行)错误
gui_mainfcn(gui_State,varargin {:});

错误@(hObject,eventdata)untitled('popFreqResp_Callback',hObject,eventdata,guidata(hObject))


评估uicontrol时出错回调

代码片段

  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


解决方案

使用'==',因为如果字符串不是相同的长度,它会抛出错误。基本上'=='是比较两个字符类型的字符 - 如果他们没有相同的长度,'=='没有定义。由于'低通'的长度为8,'Band Pass'的长度为9,所以你不能以这种方式比较它们。



使用 strcmp 代替。或者 strcmpi ,如果你不在乎的话。


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

解决方案

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.

这篇关于矩阵维度必须一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆