how to call some columns and fprintf ???
5 ビュー (過去 30 日間)
古いコメントを表示
i have text file contains 50 columns and 50 rows , for example how i want print column 2 4 5 45
0 件のコメント
回答 (1 件)
dpb
2014 年 3 月 2 日
編集済み: dpb
2014 年 3 月 2 日
This essentially identical to the previous question I answered...
i want print column 2 4 5 45
Given array x of 50x50, say, and
icol=[2 4 5 45];
fmt=[repmat('%.3f ',1,length(icol)) '\n'];
fprintf(fid,fmt,x(:,icol).')
...
Again, salt to suit for formatting, etc., ...
ADDENDUM:
Unless the question is simply one of how to reference a subset of an array in which case the answer is embedded in the above by use of the predefined column index vector. This is basic Matlab syntax; if you don't understand that, go to the "Getting Started" section and work thru the basic addressing exercises.
NB: the line you've commented as giving an error is owing to the bad syntax that attempted to store the colon operator in the d vector. That may seem like a reasonable thing to try to do, but it is simply not supported by Matlab syntax.
d=(:,[2 4 5 45]); % you can't do this--invalid syntax w/ the 'colon'
Use the form demonstrated above instead.
NB2: You can't use
irow=[2 23 92];
icol=[2 4 5 45];
z=x(irow,icol);
however, despite it looking ok and being a desirable thing to do. In that case you'll have to use the two vectors as arguments to sub2ind. See the documentation for details on the whys and hows of that.
3 件のコメント
Image Analyst
2014 年 3 月 6 日
dpb, it seems like he deleted a comment before yours. All that's there now is his "original" question "i have text file contains 50 columns and 50 rows , for example how i want print column 2 4 5 45", which actually I'm not so sure now is original.
dpb
2014 年 3 月 6 日
Who knows???? Seems to have gone away and to be rather inconsiderate of those trying to help, anyway...
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!