フィルターのクリア

prevent function from displaying output

3 ビュー (過去 30 日間)
pemfir
pemfir 2012 年 9 月 28 日
I have the following function (please do not suggest that i change the function itself):
function [sumf] = delet();
for i = 1:2;
syms d u ;
f = (char(vpa(subs((d/u - strcat('k',num2str(i))),{d,u},{1,2}))));
a = symvar(char(vpa(f)));
f = ['@(', sprintf('%k1,', a{1:end-1}), a{end}, ') ',f];
f = eval(f);
x = strcat('f',num2str(i));
eval(sprintf('%s = f',x));
end
sumf = @(k) f1(k(1))+f2(k(2));
once called : f = delet; f = delet;
f =
0.5 - 1.0*k1
f1 =
@(k1)0.5-1.0*k1
f =
0.5 - 1.0*k2
f2 =
@(k2)0.5-1.0*k2
on the display. how do i stop this ?
  1 件のコメント
Razvan
Razvan 2012 年 9 月 28 日
What exactly do you want to stop? Your question is very unclear... Probably you want to remove the
eval(sprintf('%s = f',x));
line, if you don't want this to display your functions...

サインインしてコメントする。

採用された回答

Razvan
Razvan 2012 年 9 月 28 日
f = delet;
  2 件のコメント
pemfir
pemfir 2012 年 9 月 28 日
編集済み: pemfir 2012 年 9 月 28 日
please try the following. my mistake i uploaded a bad example:
function [f] = delet();
f1 = @(x) x^2 + 3;
f2 = @(x) x^2 + 3;
f = @(x) f1(x(1))+f2(x(2));
once called : f = delet;
f =
@(x)f1(x(1))+f2(x(2))
Razvan
Razvan 2012 年 9 月 28 日
you have to put semicolon in the body of the function too:
f = @(x) f1(x(1))+f2(x(2));

サインインしてコメントする。

その他の回答 (3 件)

Wayne King
Wayne King 2012 年 9 月 28 日
Put a semicolon after delet when you call the function
f = delet;
  1 件のコメント
pemfir
pemfir 2012 年 9 月 28 日
編集済み: pemfir 2012 年 9 月 28 日
please try the following. my mistake i uploaded a bad example:
function [f] = delet();
f1 = @(x) x^2 + 3;
f2 = @(x) x^2 + 3;
f = @(x) f1(x(1))+f2(x(2));
once called : f = delet;
f =
@(x)f1(x(1))+f2(x(2))

サインインしてコメントする。


Daniel Shub
Daniel Shub 2012 年 9 月 28 日
Are you trying to evaluate the function? Do you want f()?
  1 件のコメント
pemfir
pemfir 2012 年 9 月 28 日
i will use it in fsolve

サインインしてコメントする。


Muthu Annamalai
Muthu Annamalai 2012 年 9 月 28 日
Changes, like the previous comments suggest, using a semi-colon, should stop output form appearing on your terminal.
Also you want to explore 'str2func()' as a way to build function handles.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by