modify shape of char array

3 ビュー (過去 30 日間)
Matteo Niccoli
Matteo Niccoli 2015 年 1 月 6 日
編集済み: Matteo Niccoli 2015 年 1 月 6 日
I have this 10x6 character array:
250F20
271022
291124
2B1326
2E1429
2E1532
2D153C
2D1743
2D184D
2D1954
I would like to convert it to a 10x1 array where each element is a 6-character string. I got what I wanted with a cell array of strings:
cc=cellstr(array);
But I wonder why something like this would not work:
[a,b] = size(array);
for i=1:a
s(i)= strcat(array(i,1),array(i,2),array(i,2),array(i,3),array(i,4),array(i,5),array(i,6));
end
clear i

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 6 日
Use s{} instaed of s()
[a,b] = size(array);
for i=1:a
s{i,1}= strcat(array(i,1),array(i,2),array(i,2),array(i,3),array(i,4),array(i,5),array(i,6))
end
  1 件のコメント
Matteo Niccoli
Matteo Niccoli 2015 年 1 月 6 日
編集済み: Matteo Niccoli 2015 年 1 月 6 日
Hi Azzi, thank you - of course! - it worked. Further question: assuming I vectorized your recommended solution, which one would be preferable, the latter, or
cc=cellstr(array);

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

その他の回答 (0 件)

カテゴリ

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