Effacer les filtres
Effacer les filtres

How to join data from the row of a matrix? or transform a row in a vector?

2 vues (au cours des 30 derniers jours)
Want to join data in one data row, for example I have this array
d = ['0021008'; 'FFFFFFF'; '0021008']
When applying d (3) MATLAB gives me the value of "F",
but I wondered how I could merge all data into one row and when I ask d (3), MATLAB returns me "FFFFFFF"
Thank you very much, I hope you can help me
Greetings from Mexico.

Réponse acceptée

the cyclist
the cyclist le 15 Août 2011
Your syntax is merging those three strings into one long string. Instead, you might want to try a cell array:
d = {'0021008'; 'FFFFFFF'; '0021008'}
Note the curly brackets instead of square brackets. See the documentation for more help on using cell arrays.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 15 Août 2011
That is not possible in MATLAB, at least not without writing a specific object-oriented class that overrides the behavior of () indexing.
In MATLAB, () with a single subscript returns an individual array element. In MATLAB, character strings are arrays of characters, not individual {group} elements. Therefor, d(3) applied to any kind of character array can only return a single character.
You could use d(3,:) to get the row.
The other thing you could do is use
dt = cellstr(d);
After that, dt(2) would be {'FFFFFFF'} which would be a 1 x 1 cell array that contains the character array 'FFFFFFF'. dt{2} (notice the {} instead of () ) would be 'FFFFFFF' the character array.
Using cell arrays, it is possible to have an array d such that d{3} with {} brackets returns a character string, but d(3) with the usual () brackets would not be a character string.
  1 commentaire
Victor Haro
Victor Haro le 15 Août 2011
Roberson, thank you very much, your help is useful to me,
greetings from Mexico, good luck!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings 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