Borrar filtros
Borrar filtros

how to call some columns and fprintf ???

1 visualización (últimos 30 días)
Adam Aust
Adam Aust el 2 de Mzo. de 2014
Comentada: dpb el 6 de Mzo. de 2014
i have text file contains 50 columns and 50 rows , for example how i want print column 2 4 5 45

Respuestas (1)

dpb
dpb el 2 de Mzo. de 2014
Editada: dpb el 2 de Mzo. de 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 comentarios
Image Analyst
Image Analyst el 6 de Mzo. de 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
dpb el 6 de Mzo. de 2014
Who knows???? Seems to have gone away and to be rather inconsiderate of those trying to help, anyway...

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by