Insert elements to cell array

70 Ansichten (letzte 30 Tage)
NA
NA am 12 Okt. 2020
Beantwortet: Stephen23 am 12 Okt. 2020
I have cell array g like this:
{'A'} {[1]} {[1]} {[1]}
{'B'} {[1]} {[2]} {[1]}
{'C'} {[2]} {[3]} {[2]}
{'D'} {[1]} {[4]} {[1]}
{'E'} {[1]} {[5]} {[1]}
I have M=[31,2].
How can I insert M to the first column of g.
Result should be
{31,2} {'A'} {[1]} {[1]} {[1]}
{31,2} {'B'} {[1]} {[2]} {[1]}
{31,2} {'C'} {[2]} {[3]} {[2]}
{31,2} {'D'} {[1]} {[4]} {[1]}
{31,2} {'E'} {[1]} {[5]} {[1]}

Akzeptierte Antwort

Stephen23
Stephen23 am 12 Okt. 2020
g = g(:,[1,1:end]);
g(:,1) = {M}

Weitere Antworten (1)

Matt J
Matt J am 12 Okt. 2020
Bearbeitet: Matt J am 12 Okt. 2020
g=[ repmat({M},5,1) , g]

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by