MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]edittext的数值怎样传递入公式运算? (https://www.labfans.com/bbs/showthread.php?t=3867)

yangn2003 2008-07-10 19:59

[求助]edittext的数值怎样传递入公式运算?
 
2 个附件
我想通过edittext,让用户输入一个数值w,坐标轴横轴为se,纵轴为sa, w=se/sa,绘制出坐标图,edittext命名为ex73_etext, 按钮命名为ex_plot, 用户输入数值后按按钮显示图形,可是w的值好像总是不能顺利传进计算式,图形显示不出来,请问问题出在哪里?


function ex73_etext_Callback(hObject, eventdata, handles)
[COLOR="DarkGreen"]% hObject handle to ex73_etext (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ex73_etext as text
% str2double(get(hObject,'String')) returns contents of ex73_etext as a double


% --- Executes during object creation, after setting all properties.[/COLOR]
function ex73_etext_CreateFcn(hObject, eventdata, handles)
[COLOR="darkgreen"]% hObject handle to ex73_etext (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.[/COLOR]if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


[COLOR="darkgreen"]% --- Executes on button press in ex73_plot.[/COLOR]
function ex73_plot_Callback(hObject, eventdata, handles)
[COLOR="darkgreen"]% hObject handle to ex73_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)[/COLOR]
[COLOR="Red"]flag=get(handles.ex73_etext,'Value');[/COLOR] [COLOR="darkgreen"]%get the value of the edittext[/COLOR]
[COLOR="red"]w=[str2double(flag),'Value'];[/COLOR]
t=0:0.001:2*pi; [COLOR="darkgreen"] %define the array t[/COLOR]
se=1;

[COLOR="red"]sa=w*(se*t);[/COLOR] [COLOR="red"]问题所在[/COLOR]


axes(handles.ex73_axes) [COLOR="darkgreen"]%claim the graph drawed on the ex71_axes[/COLOR]
plot(se*t,sa)


错误显示:
Warning: Out of range or non-integer values truncated during conversion to character.
> In ex73>ex73_plot_Callback at 106
In gui_mainfcn at 75
In ex73 at 42
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> ex73>ex73_plot_Callback at 110
sa=w*(se*t);

Error in ==> gui_mainfcn at 75
feval(varargin{:});

Error in ==> ex73 at 42
gui_mainfcn(gui_State, varargin{:});

??? Error using ==> ex73('ex73_plot_Callback',gcbo,[],guidata(gcbo))
Error using ==> mtimes
Inner matrix dimensions must agree.

??? Error while evaluating uicontrol Callback


所有时间均为北京时间。现在的时间是 14:24

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.