【问题标题】:Reference to non-existent field handles matlab引用不存在的字段句柄 matlab
【发布时间】:2017-09-09 07:54:08
【问题描述】:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
f=imread('/Users/MoChutima/Desktop/WORK1:2560/ImageProcess/dip/dip/baboon.jpg');
Tscale = [handles.sx 0 0; 0 handles.sy 0; 0 0 1];
Trotation = [cos(handles.theta) sin(handles.theta) 0; -sin(handles.theta) cos(handles.theta) 0; 0 0 1];
Tshear = [1 handles.shx 0; handles.shy 1 0; 0 0 1];
T=Tscale*Trotation*Tshear;
tform=maketform('affine',T);
g=imtransform(f,tform,'bilinear');
imshow(g);

我有错误

Error in Workex63>pushbutton1_Callback (line 82)
Tscale = [handles.Sx 0 0; 0 handles.Sy 0; 0 0 1];

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

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

Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Workex63('pushbutton1_Callback',hObject,eventdata,guidata(hObject)) 

评估 UIControl 回调时出错

我在 GUI 中做几何,我想创建滑块并编辑文本以填充剪切 X、Y 缩放 X、Y 的数量,但现在我无法加载图片进行处理。

谢谢

【问题讨论】:

  • 您好,欢迎来到 SO!我们在这里帮助编写更好的代码。正如目前所说,我们几乎不可能重现您的问题,因此您可能不会收到很多回复。此外,它看起来更像是直接复制粘贴您的代码+输出,而不应用标准调试技术,这通常不是我们在这里所做的。请阅读有关如何编写minimal working examplewhat kinds of questions you can ask here 的常见问题解答。

标签: matlab matlab-guide


【解决方案1】:

实际上,我认为您将控件(文本框、复选框等)与其基础价值混淆了。

例如,假设handles.theta 引用Slider 控件,handles.ssomething 引用EditText 控件,用户可以在其中插入数值。如果您想检索它们的值并使用它们来处理您的计算,您必须这样做:

th = get(handles.theta,'Value');
ss = str2double(get(handles.ssomething,'String'));

或者(也一样,但我更喜欢这种方式):

th = handles.theta.Value;
ss = str2double(handles.ssomething.String);

因此,要修复您的代码,首先从应用程序控件中检索您需要的所有数值,然后继续计算:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

th = handles.theta.Value;
shx = str2double(handles.shx.String);
shy = str2double(handles.shy.String);
sx = str2double(handles.sx.String);
sy = str2double(handles.sy.String);

f = imread('myimage.jpg');
Tscale = [sx 0 0; 0 sy 0; 0 0 1];
Trotation = [cos(th) sin(th) 0; -sin(th) cos(th) 0; 0 0 1];
Tshear = [1 shx 0; shy 1 0; 0 0 1];
T=Tscale*Trotation*Tshear;
tform=maketform('affine',T);
g=imtransform(f,tform,'bilinear');
imshow(g);

不要忘记通过Callback 在您的EditText 控件中实施健全性检查,以验证用户的输入(并防止插入错误的值)。这不是问题的一部分,但我很确定您会在谷歌上找到数百个示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多