fprintf array: how to ignore cells when displaying?

1 view (last 30 days)
Amar
Amar on 30 Mar 2014
Commented: Amar on 30 Mar 2014
Using a single fprintf function, how can I ignore zeros in a 2d array and move on to displaying the ones following? To be specific, here is what I got:
x=[0.2 0.4 0.6 0.8 1.0];
y=[12 53 123 11 0;11 4 12 90 0 0];
fprintf('x %f\t%f\t%f\t%f\t%f\t\nf1(x) %f\t%f\t%f\t%f\t _{%display white space equivalent of 1 data points here%}_ /nf2(x) %f\t%f\t%f\t _{%display white space equivalent of 2 data points here%}_ /n ',x,y);
The result should look something like this:
Thanks and do let me know if I can make this code more efficient too.

Answers (1)

Image Analyst
Image Analyst on 30 Mar 2014
Often in MATLAB to get it to ignore things, you can set them to nan:
zeroLocations = array2D == 0;
array2D(zeroLocations) = nan;
I have no idea what f1 and f2 are, and your code does not run so I'm not sure what to do with it.
  3 Comments
Image Analyst
Image Analyst on 30 Mar 2014
But your y line is not even right. There's an error when you try to assign y.
Amar
Amar on 30 Mar 2014
I'm sorry, I just filled random numbers in my questions cuz of laziness, while in the result pasted above is the real results. Assume that it is correct, can I eliminate the x and the three NaNs somehow?

Sign in to comment.

Categories

Find more on Programming 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!