フィルターのクリア

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

2 ビュー (過去 30 日間)
Victor Haro
Victor Haro 2011 年 8 月 15 日
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.

採用された回答

the cyclist
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.

その他の回答 (1 件)

Walter Roberson
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.
  1 件のコメント
Victor Haro
Victor Haro 2011 年 8 月 15 日
Roberson, thank you very much, your help is useful to me,
greetings from Mexico, good luck!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by