Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

the cyclist
the cyclist el 15 de Ag. de 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.

Más respuestas (1)

Walter Roberson
Walter Roberson el 15 de Ag. de 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 comentario
Victor Haro
Victor Haro el 15 de Ag. de 2011
Roberson, thank you very much, your help is useful to me,
greetings from Mexico, good luck!

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings 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