fprintf array: how to ignore cells when displaying?

2 ビュー (過去 30 日間)
Amar
Amar 2014 年 3 月 30 日
コメント済み: Amar 2014 年 3 月 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 件のコメント
Amar
Amar 2014 年 3 月 30 日
See my comment below for update on the problem

サインインしてコメントする。

回答 (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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by