Effacer les filtres
Effacer les filtres

C(:,s) = g(:); what values of g will be stored in C(:,s)?

1 vue (au cours des 30 derniers jours)
Shan Sha
Shan Sha le 7 Sep 2018
C(:,s) = g(:); what values of g will be stored in C(:,s)? how it will be stored in C(:,s)? will this colon differs for every new line?

Réponses (1)

Walter Roberson
Walter Roberson le 7 Sep 2018
C(:,s) = g(:); what values of g will be stored in C(:,s)
All values of g will be stored. If C is not initialized yet then numels(g) will define the number of rows to be created in C. If C is already initialized then if numels(g) does not match the number of rows already in C then you would get an error.
how it will be stored in C(:,s)?
g(:) reshapes the entries of g into a single column vector. The order in the column vector is the order that the entries originally occurred in memory. MATLAB stores in "column major order", so g(1,1) is followed by g(2,1) then g(3,1) and so on down column 1, and then immediately after that in memory would be the first item of column 2, g(1,2), then g(2,2), g(3,2) and so on.
will this colon differs for every new line?
I do not think I understand the question, but, No: see what I wrote above about if C is already initialized. You would have to have the same number of total entries in g in order to do the storing. This does not require that g have the same shape each time. For example,
g = [1 2 3 4]; C(:,1) = g(:);
g = [1 2; 3 4]; C(:,2) = g(:); %valid because g has the same number of total entries and those get reshaped to a column vector before trying to store

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by