首页 文章

引用不存在的字段处理matlab

提问于
浏览
0
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的数量,但现在我无法加载图片来处理 .

谢谢

1 回答

  • 0

    实际上,我认为你的控件(文本框,复选框等)与它们的基础值混淆 .

    例如,假设 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);
    

    不要忘记通过 CallbackEditText 控件中执行完整性检查,以验证用户的输入(并防止插入错误的值) . 这不是问题的一部分,但我很确定你会发现数百个谷歌搜索的例子 .

相关问题