Effacer les filtres
Effacer les filtres

Storing 2 values in one location of matrix with a space

9 vues (au cours des 30 derniers jours)
Phong Pham
Phong Pham le 11 Juil 2016
Modifié(e) : Tyler le 11 Juil 2016
Hi everyone,
I want to store 2 values in one location of matrix with a space between them.
For example:
A = [ 1; 2; 3; 4; 5]
I want A(1,1) to have 2 values with a space between them. Let say I want A to be like this
A = [1 1; 2; 3; 4; 5]
I was trying to use A(1,1) =str2num([num2str(1),num2str(1)]) but they have no space so A(1,1) is 11 instead of 1 1.
Thanks.
  1 commentaire
Stephen23
Stephen23 le 11 Juil 2016
Modifié(e) : Stephen23 le 11 Juil 2016
"Let say I want A to be like this"
A = [1 1; 2; 3; 4; 5]
You can't, because that is not a numeric matrix: every element of a numeric matrix is exactly one numeric value. As the documentation for Create Numeric Arrays states: "All rows must have the same number of elements".
If you really need to store a different number of values in each element, then you can use a cell array.

Connectez-vous pour commenter.

Réponses (1)

Tyler
Tyler le 11 Juil 2016
Modifié(e) : Tyler le 11 Juil 2016
Stephen is right, the only way to do that is with a cell array.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by