how to fprintf vectors of symbolic function with parentheses
1 view (last 30 days)
Show older comments
Hi all,
I am using fprintf to output a vector of symbolic function, here is a piece of my code:
fvec = sym('fvec', [1 N]);
for j=1:1:N
fprintf(fileID, '%s\n', char(fvec(j)));
end
but this gives me fvec1, fvec2,.... fvecN. How could I get an output containing fvec(1), fvec(2),...fvec(N) instead? Thank you.
0 Comments
Answers (1)
Walter Roberson
on 10 Dec 2013
fprintf(fileID, 'fvec(%d)\n', j);
fvec(j) is going to do a value lookup, just the same way as it would for numeric values. The value associated with fvec(j) is the sym() that was generated from it. You used the form that generates 'fvec' immediately followed by a number as the value of each element.
If you had used sym('fvec(%d)', [1 N]) then you might perhaps get 'fvec(1)' and so on, but I am not positive of that (I do not have the toolbox to test with.) If you do, keep in mind that in the internal symbolic language, that would normally signify a function call rather than a subscript. The internal symbolic language uses [] for subscripting, 'fvec[%d]' .
0 Comments
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!