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
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
2014 年 3 月 30 日
But your y line is not even right. There's an error when you try to assign y.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!