How to output entire columns of a cell array?
Afficher commentaires plus anciens
I have this cell array and I want to output an entire column from the workspace.
The function goes like this,
function Time = Rin
fid = fopen( 'Rincon.txt' );
Time = textscan( fid, '%d%d%d%d%d%f%f%f%f%f%s%s%s%f%f' ...
, 'Delimiter' , ' ' ...
, 'CollectOutput' , true ...
, 'HeaderLines' , 2 ...
, 'MultipleDelimsAsOne' , true ...
, 'Whitespace' , '' ...
);
fclose( fid );
end
When Run, the output is this,
ans =
[2163x5 int32] [2163x5 double] {2163x3 cell} [2163x2 double]
I want to illustrate on the Command Window the entire first column of the array, ans {1,2}
Can you please help?
4 commentaires
Azzi Abdelmalek
le 24 Déc 2012
Modifié(e) : Azzi Abdelmalek
le 24 Déc 2012
Why ans{1,2}?, it's ans{2}
Walter Roberson
le 24 Déc 2012
Azzi, cell references follow the same rules as normal array locations do -- that A{2} refers to the second element of A, which would correspond to A(2,1) if A is an array or a column vector and would correspond to A(1,2) if A is a row vector. A{2} is the linear indexing form, but the underlying indexing model is the A(1,2) or A(2,1) form. In other words, ans{1,2} is completely correct and is considered in a way more "right" than ans{2}
Azzi Abdelmalek
le 24 Déc 2012
Walter, What do you mean by more right, and what will you win by adding two character (A(1,2) instead of A(2)), also why not A(1,2,1)?
Jan
le 24 Déc 2012
@Azzi: If you have an indexing bug in a program and confuse column with row vectors, using the explicit C{1,2} indexing can help to locate the problem. But this costs some processing time and it is less "nice".
The linear indexing is efficient for matrices also:
M = rand(2,2)
disp(M(4))
But this must be applied carefully and the explicite indexing is in most cases easier to debug. So finally, A{2} or A{1,2} is equivalent and it is a question of taste and the choice might depend on the decision, if the run time or the debug time is more important.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!