Hey I'm trying to do something... and I don't know if it's possible :s
I'm currently drawing on subfunctions and showing the result via fprintf, however I want to simplify it if I can.
If my code has the following;
fprintf('My results are %.5f and %.5f' f(x), (f(x)/2))
Is there anyway to avoid having to state "f(x)" twice? I know I could define it earlier by something like "a = f(x)" and then have the fprintf have "a, a/2" but I want to keep as much of the code as I can in the fprintf.
Is there any way I can do this? I would assume not, but MATLAB has supprised me before!
I appretiate the help and if any more details are needed just ask :)

 채택된 답변

Sean de Wolski
Sean de Wolski 2012년 3월 14일

1 개 추천

fprintf('My results are %.5f and %.5f', f(x)./[1, 2])
Hey, it's not a better solution but it meets your requirements.

댓글 수: 3

Stephen
Stephen 2012년 3월 14일
Thank you very much, that is much better :D My subfunction has around 6 variables and so this helps simplify it! I assume it's broken down as;
f(x) states the function, or whatever
Then ./ divides
[1, 2] first divides by 1 then by 2 and gives the two new values in a row vector which then get fed into the fprintf
?
Sorry for the potentially niave questions, started learning how to use MATLAB last year and I've found it's good to learn what does what and how/why :D
Sean de Wolski
Sean de Wolski 2012년 3월 14일
yup that's basically it!
Stephen
Stephen 2012년 3월 14일
Thank you very much for the help :) Much appretiated :D

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by