# converting 3D double matrix to char matrix

7 ビュー (過去 30 日間)
sermet OGUTCU 2021 年 11 月 21 日
コメント済み: sermet OGUTCU 2021 年 11 月 21 日
matrix_double_3D= 286 x 1 x 32
such as:
val(:,:,1) =
1
1
.
val(:,:,2) =
2
2
.
I need to convert this matrix to char matrix with adding prefix (G) to the numbers such as:
val(:,:,1) =
G1
G1
val(:,:,2) =
G2
G2
I attached the original matrix_double_3D data. .

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

### 採用された回答

DGM 2021 年 11 月 21 日
You can do this as a cell array of chars, or you can do it with an actual char array if you really must. Another option would be a string array, if that works for your needs.
G = S.GPS_reference_PRN_double_original_epochs_3D;
% as a cell array
Gcl = num2cell(G);
Gcl = cellfun(@(x) sprintf('G%d',x),Gcl,'uniform',false);
Gcl(1:3,:,1:3) % show a sample
ans = 3×1×3 cell array
ans(:,:,1) = {'G1'} {'G1'} {'G1'} ans(:,:,2) = {'G2'} {'G2'} {'G2'} ans(:,:,3) = {'G3'} {'G3'} {'G3'}
% as a fragile char array
% assumes absval of numbers are less than 100
Gch = permute(reshape(sprintf('G%02d',G),3,size(G,1),size(G,3)),[2 1 3]);
Gch(1:3,:,1:3) % show a sample
ans = 3×3×3 char array
ans(:,:,1) = 'G01' 'G01' 'G01' ans(:,:,2) = 'G02' 'G02' 'G02' ans(:,:,3) = 'G03' 'G03' 'G03'
##### 1 件のコメント表示非表示 なし
sermet OGUTCU 2021 年 11 月 21 日
Thanks a lot

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

### カテゴリ

Find more on Operators and Elementary Operations 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!

Translated by