fprintf array: how to ignore cells when displaying?

2 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2014-3-30
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 个评论
Image Analyst
Image Analyst 2014-3-30
But your y line is not even right. There's an error when you try to assign y.
Amar
Amar 2014-3-30
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by