How can I print sparse inputs using fprintf() in MATLAB 2013?

13 views (last 30 days)
While using command: fprintf('%4g', p); fprintf('%4g', q);
(where, p=Real power & q=Reactive power)
it shows proper results in MATLAB 2009.
But with MATLAB 2013, it shows an error like: "Error using fprintf.
Function is not defined for sparse inputs."
How can I print required datas in MATLAB 2013 using "fprintf()" OR any other command ??

Answers (2)

Jan
Jan on 6 Apr 2015
Even under Matlab 2009a fprintf does not work with sparse arrays. So the problem seems to be, that your p and q are sparse in MATLAB 2013, while it is not sparse in MATLAB 2009. How did you create these variables?
If the arrays are small, this will help:
fprintf('%4g', full(p));
fprintf('%4g', full(q));
  2 Comments
Dipesh Doshi
Dipesh Doshi on 13 Aug 2016
I tried to use whatever u told like
fprintf('%4g', full(p)); fprintf('%4g',full(q));
though it shows the same error and I am using 14 bus system... tell me how to resolve it
Jan
Jan on 28 Sep 2016
@Dipesh Doshi: If you use the FULL() command, FPRINTF doe not get sparse inputs. Thefore you cannot get the same error message, at least not in this line. Please post an example with data, which reproduces the problem.

Sign in to comment.


RAKOTOMANANIAINA Dimby Mahefa
try this
fprintf('%4g',p); fprintf('%4g', q); fprintf(' %8.3f', full(Pij(p,q))); fprintf(' %8.3f', full(Qij(p,q)));
fprintf(' %4g', q); fprintf('%4g', p); fprintf(' %8.3f', full(Pij(q,p))); fprintf(' %8.3f', full(Qij(q,p)));
the error is in : fprintf(' %8.3f', Pij(p,q)); fprintf(' %8.3f', Qij(p,q)); and fprintf(' %8.3f', Pij(q,p)); fprintf(' %8.3f', Qij(q,p));

Tags

Products

Community Treasure Hunt

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

Start Hunting!