Insert numeric values (rx1 matrix) inside a cell

2 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2022 年 12 月 10 日
コメント済み: Stephen23 2022 年 12 月 11 日
Hi. I would like to insert a column of 100:
rep = repmat(100,157,1);
inside the first cell (see image) so that 157x2 becomes 157x3.
The third column represents "rep".
How can I do this?

採用された回答

Arif Hoq
Arif Hoq 2022 年 12 月 10 日
a=randi(100,157,2);
b=randi(200,189,2);
c=randi(300,183,2);
mat={a;b;c} % making a cell array
mat = 3×1 cell array
{157×2 double} {189×2 double} {183×2 double}
% rep = repmat(100,157,1);
mat3={[mat{2,1} repmat(100,size(mat{2,1},1),1)]};
for i=1:size(mat,1)
aaa(i)={[mat{i,1} repmat(100,size(mat{i,1},1),1)]};
end
output=aaa'
output = 3×1 cell array
{157×3 double} {189×3 double} {183×3 double}
  2 件のコメント
Alberto Acri
Alberto Acri 2022 年 12 月 10 日
Thank you for the answer. I don't want to insert the same value 100 to all cells.
At the first cell (157x2) I need to insert the third column of all 100.
At the second cell (189x2) I need to insert the third column of all 150.
At the third cell (183x2) I must insert the third column of all 200.
Arif Hoq
Arif Hoq 2022 年 12 月 10 日
tyr this:
a=randi(100,157,2);
b=randi(200,189,2);
c=randi(300,183,2);
mat={a;b;c}; % making a cell array
% rep = repmat(100,157,1);
% mat3={[mat{2,1} repmat(100,size(mat{2,1},1),1)]};
for i=1:size(mat,1)
if i==1
aaa(i)={[mat{i,1} repmat(100,size(mat{i,1},1),1)]};
elseif i==2
aaa(i)={[mat{i,1} repmat(150,size(mat{i,1},1),1)]};
elseif i==3
aaa(i)={[mat{i,1} repmat(200,size(mat{i,1},1),1)]};
end
end
output=aaa';

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by