set of equations printing using sprintf command

조회 수: 2 (최근 30일)
Kallam Haranadha Reddy
Kallam Haranadha Reddy 2017년 9월 12일
편집: Stephen23 2017년 9월 12일
i want to print the following set of equations using sprintf command.
p=1,2,...,8
c=1,2,..,4
t = 1,2,...,12,
m= 1,2.
see the attachment file for the equation.
Note: D(p,c,t) is a number (input data).
  댓글 수: 3
OCDER
OCDER 2017년 9월 12일
I agree, this eqn in the txt file is hard to understand:
?_(m?D(c))??tc?_pmct = D_?(pct@) - ?tar?_?(pct@ ) for all p,c,t.
Also, the range of values of p, c, t, m are all different. Do you want (8x4x12x2) combinations of an equation?
Stephen23
Stephen23 2017년 9월 12일
편집: Stephen23 2017년 9월 12일
@Mechanical Engineering: what you seem to be trying to do is access a whole lot of variable names dynamically. This is a terrible way to write code: slow, pointlessly complex, buggy, hard to follow, hard to debug, and insecure: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
As a much better alternative you should really learn about indexing, which is simple, neat, easy to debug, and very efficient.
If you want to use MATLAB why are you mucking about with strings? Encoding data into strings and trying to parse them is an awfully complex and inefficient way to write code. Instead, why not learn how to use MATLAB, and use numeric arrays and indexing?
I would recommend that you actually tell us what your task is, rather than wasting time asking us how to do awkward and ugly code like that. Your question seems to be an example of the X-Y problem:
and you would get much better results and we would all save a lot of time if you simply explained what your goal is.

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

답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by