i'd like to append variable n0 to n1
but this code made just last variable
Thanks!
leng=length(list)
n0=[]
for i=1:leng
nl=list(i).name
end

6 Kommentare

Stephen23
Stephen23 am 18 Feb. 2022
No need to use a loop:
{list.name} % to place into a cell array
[list.name] % to concatenate together
il147
il147 am 18 Feb. 2022
Thanks, but length of list is 10 so I want to make name list like 10 by 1(10*1)
Stephen23
Stephen23 am 18 Feb. 2022
Bearbeitet: Stephen23 am 18 Feb. 2022
vertcat(list.name) % concatenate elements
[list.name].' % concatenate elements
{list.name}.' % place elements into a cell array
il147
il147 am 18 Feb. 2022
Sorry but my 'name' is 'char' so it didn't work vercat
Anyway Thanks!
Stephen23
Stephen23 am 18 Feb. 2022
That is why I showed you this approach:
{list.name}.'
Much simpler than a loop.
il147
il147 am 18 Feb. 2022
It works!!!! Thanks for your help!!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

KSSV
KSSV am 18 Feb. 2022
Bearbeitet: KSSV am 18 Feb. 2022

0 Stimmen

You can make it a cell array.
leng=length(list)
nl = cell(leng,1) ;
for i=1:leng
nl{i}=list(i).name
end
You may access n1{1}.........n1{10}

3 Kommentare

il147
il147 am 18 Feb. 2022
Thanks, And Is there any code that append name to empty list(n0)
KSSV
KSSV am 18 Feb. 2022
You can do the same as shown above. Store them into a cell array.
il147
il147 am 22 Feb. 2022
Do you have any idea to make it matrix form not cell array?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 18 Feb. 2022

Kommentiert:

am 22 Feb. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by