Clear Filters
Clear Filters

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

2 views (last 30 days)
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.

Accepted Answer

the cyclist
the cyclist on 15 Aug 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.

More Answers (1)

Walter Roberson
Walter Roberson on 15 Aug 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.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!