for loop save variables as matirx

I have excel file for annual data and I just want save my data name in name0
but name0 just have last name of my data
how can i save all name in matrix form?
Thanks!
list=dir('C:\Users\pc\Desktop\*.xlsx');
leng=length(list);
name=[];
for i=2:leng
namel=list(i).name
name0=cat(2,name,namel);
end

1 件のコメント

Stephen23
Stephen23 2022 年 2 月 22 日
編集済み: Stephen23 2022 年 2 月 22 日
"how can i save all name in matrix form?"
Although you underlined the text "in matrix form", you did not explain how that "matrix form" would be any different to the answers you got to your duplicate question here:
Please show or explain how a "matrix form" would be different from the normal, standard, easy approach of using a cell array.

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

回答 (1 件)

KSSV
KSSV 2022 年 2 月 22 日

0 投票

list=dir('C:\Users\pc\Desktop\*.xlsx');
leng=length(list);
name=cell(leng,1);
for i=2:leng
name{i} = list(i).name
end
The above is nothing but:
name = {list.name}

3 件のコメント

il147
il147 2022 年 2 月 22 日
Thanks agin
but this time I want to use empty matrix and 'cat'
KSSV
KSSV 2022 年 2 月 22 日
Why? Each name will vary, it is a string. So you have to save it into a cell.
il147
il147 2022 年 2 月 22 日
I didn't know string have to save into cell
becasue I always make it like that with not string
Thanks for help!

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2022 年 2 月 22 日

コメント済み:

2022 年 2 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by