function pushbutton1_Callback(hObject, eventdata, handles)
f1 = str2double(get(handles.a,'String'));
f2 = str2double(get(handles.b,'String'));
f3= str2double(get(handles.c,'String'));
f4 = str2double(get(handles.d,'String'));
f5 = str2double(get(handles.e,'String'));
f4=0:0.1:10;
set(handles.d, 'enable', 'off')
contents = cellstr(get(handles.popupmenu1, 'String'));
f6 = contents{get(handles.popupmenu1, 'Value')};
x = f1* sin(2*pi*f2+f3);
y = f1 * cos(2*pi*f2+f3);
plot(handles.axes1,x,[0,f4]);
plot(handles.axes1,y,[0,f4]);
I've made this code, but I can't find the graph even if I enter the value to fix it's not working.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 6월 27일

0 개 추천

x = f1* sin(2*pi*f2+f3);
All of those variables are scalars so x will be a scalar
y = f1 * cos(2*pi*f2+f3);
Likewise for y, it will be a scalar
plot(handles.axes1,x,[0,f4]);
Your independent variable x is a scalar. Your dependent variable [0,f4] is a vector. At most you would end up with a number of line segments drawn at a constant x and different y values.
[0,f4] as the dependent parameter does not tell plot() to evaluate a formula over the given rangeb that kind of functionality would be fplot() not plot(). But your independent variable x is not a formula, it is a numeric scalar.
You should be evaluating sin() at an expression that includes the vector f4, and your plot should be using f4 as the independent variable and the result of sin as the dependent variable.
You should be using f6 to decide whether to use sin or cos, not to plot both.

댓글 수: 7

JINWOO HONG
JINWOO HONG 2020년 6월 27일
so how can i change that code
could you change it for me? ㅠㅠ
Walter Roberson
Walter Roberson 2020년 6월 27일
look back at your gui. Inside the sin or cos call, you have 2*π*SOMETHING*t . Well, your f4 is your t values.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
f1 = str2double(get(handles.a,'String'));
f2 = str2double(get(handles.b,'String'));
f3= str2double(get(handles.c,'String'));
f4 = str2double(get(handles.d,'String'));
f5 = str2double(get(handles.e,'String'));
f4=0:0.1:10;
set(handles.d, 'enable', 'off')
contents = cellstr(get(handles.popupmenu1, 'String'));
f6 = contents{get(handles.popupmenu1, 'Value')};
x = f1* sin(2*pi*f2*f4+f3);
y = f1 * cos(2*pi*f2*f4+f3);
plot(handles.axes1,x,[0,f4]);
plot(handles.axes1,y,[0,f4]);
so this is the right code?
JINWOO HONG
JINWOO HONG 2020년 6월 27일
oh i find answer
so last question
How do I get the function values overlaid on the edit1?
JINWOO HONG
JINWOO HONG 2020년 6월 27일
sir?
Walter Roberson
Walter Roberson 2020년 6월 27일
Use sprintf() or compose() or num2str() to create a character vector that contains the output you want. set the String property of the edit1 to the character vector.
But remember that you are getting out 101 values. Ask yourself whether it is a good idea to be outputing all 101 values to the edit1 .
Image Analyst
Image Analyst 2020년 6월 27일
Isn't this a duplicate of the 5 other posts?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

질문:

2020년 6월 27일

댓글:

2020년 6월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by