Insert numeric values (rx1 matrix) inside a cell
1 view (last 30 days)
Show older comments
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?
1 Comment
Accepted Answer
Arif Hoq
on 10 Dec 2022
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)
aaa(i)={[mat{i,1} repmat(100,size(mat{i,1},1),1)]};
end
output=aaa'
2 Comments
Arif Hoq
on 10 Dec 2022
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';
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB 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!