how to call some columns and fprintf ???
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i have text file contains 50 columns and 50 rows , for example how i want print column 2 4 5 45
0 Kommentare
Antworten (1)
dpb
am 2 Mär. 2014
Bearbeitet: dpb
am 2 Mär. 2014
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 Kommentare
Image Analyst
am 6 Mär. 2014
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
am 6 Mär. 2014
Who knows???? Seems to have gone away and to be rather inconsiderate of those trying to help, anyway...
Siehe auch
Kategorien
Mehr zu Data Import and Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!