Clear Filters
Clear Filters

set of equations printing using sprintf command

2 views (last 30 days)
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 Comments
OCDER
OCDER on 12 Sep 2017
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 on 12 Sep 2017
Edited: Stephen23 on 12 Sep 2017
@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.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!