필터 지우기
필터 지우기

i am trying to make a calculator in matlab gui and i add + or - and i want to add int and diff so i write the 5 lines of codes

조회 수: 1 (최근 30일)
syms x;
input=get(handles.edit3,'string');
input = strcat('@(x) ',input);
fx=str2func(input);
c=int(fx,x);
set(handles.text2,'string',char(c));
i write the 5 lines but not this one input = strcat('@(x) ',input); when i added this one my int and diff start working inside the gui what i am not geting is what is this starcat do for the int and diff and what is the @'x' mean

채택된 답변

Mehmed Saad
Mehmed Saad 2020년 5월 7일
편집: Mehmed Saad 2020년 5월 7일
suppose i want to create an anonymous function which subtract two inputs
An_fn = @(x,y) x-y;
It is equivilant to
function op = Not_An_fn(x,y)
op = x-y;
end
An_fn(1,2)
and
Not_An_fn(1,2)
will give you same output
str2func converts the string into anonymous function
suppose my string is 'x-y'
so i need to define the input arguments by @(x,y)
strcat is concatenating the input argument with the string 'x-y'
user_string = 'x-y';
strcat('@(x,y)',user_string)
ans =
'@(x,y) x-y'
Now if we apply str2func to convert it to anonymous function
fh = str2func(strcat('@(x,y)','x-y'))
fh =
function_handle with value:
@(x,y)x-y
  댓글 수: 2
Bader Herzallah
Bader Herzallah 2020년 5월 7일
ser_string = 'x-y';
strcat('@(x,y)',user_string)
ans =
'@(x,y) x-y' so in this one u made function with @(x,y) then u add to it the eqation x-y then u change it from str2fun right?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by