How to join data from the row of a matrix? or transform a row in a vector?
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
the cyclist
2011년 8월 15일
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.
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2011년 8월 15일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!