See my comment below for update on the problem
fprintf array: how to ignore cells when displaying?
1 view (last 30 days)
Show older comments
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
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
on 30 Mar 2014
But your y line is not even right. There's an error when you try to assign y.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!