repmat usage for cellarray

104 ビュー (過去 30 日間)
sermet OGUTCU
sermet OGUTCU 2021 年 11 月 18 日
回答済み: Jan 2021 年 11 月 18 日
data = 32 x 1
double_array=[repmat(data,1,286);]; %= 286 x 32 double
Now, I need to replace data with data_string as follows:
data_string = 32 x 3 char aray
Then, I need to create cell array using the above repmat operation. I tried the below but it gave error:
cell_array=repmat({data_string,1,286});
What is the proper way to construct cell_array matrix? My matlab version is 2019a.

採用された回答

Jan
Jan 2021 年 11 月 18 日
If this is what you want:
cell_array = PG01 PG02 PG03 . . . PG32
PG01 PG02 PG03 . . . PG32
. . . . . . PG32
use:
cell_array = repmat(sprintf('PG%02d', 1:32), 286, 1)
In your call:
cell_array=repmat({data_string,1,286});
you provide a cell as input of repmat. But then the number of repetitions are missing. Mayby you mean:
cell_array=repmat(data_string, 1, 286);

その他の回答 (1 件)

Chunru
Chunru 2021 年 11 月 18 日
data_string = reshape(char(32:127), 3, []) % some characters32 x 3 char aray
data_string = 3×32 char array
' #&),/258;>ADGJMPSVY\_behknqtwz}' '!$'*-0369<?BEHKNQTWZ]`cfilorux{~' '"%(+.147:=@CFILORUX[^adgjmpsvy|'
cell_array=repmat({data_string},1,3)
cell_array = 1×3 cell array
{3×32 char} {3×32 char} {3×32 char}
cell_array{3}
ans = 3×32 char array
' #&),/258;>ADGJMPSVY\_behknqtwz}' '!$'*-0369<?BEHKNQTWZ]`cfilorux{~' '"%(+.147:=@CFILORUX[^adgjmpsvy|'
  1 件のコメント
sermet OGUTCU
sermet OGUTCU 2021 年 11 月 18 日
編集済み: sermet OGUTCU 2021 年 11 月 18 日
Dear @Chunru, your codes didn't produce the result it should when using my data:
data=[1:1:32];
double_array= 1 2 3 . . . 32
1 2 3 . . . 32
. . . . . . .
1 2 3 . . . 32 == 286 x 32 double (after [repmat(data,1,286);]; )
data_string =
32×3 char array
'G01'
'G02'
'G03'
.
.
'G32'
So after the last repmat operation, cell_array should be:
cell_array = PG01 PG02 PG03 . . . PG32
PG01 PG02 PG03 . . . PG32
. . . . . . PG32

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by