How to name rows with same names?

5 ビュー (過去 30 日間)
C PRASAD
C PRASAD 2022 年 7 月 6 日
編集済み: Rohit Kulkarni 2022 年 7 月 6 日
I have data with 336*5 size.I would like to name the first 122 rows with one name and 113 to 224 with different name and 225 to 336 with another name .Also each column (5 columns) with 5 different name.Can we do this ? The data is of double type.Finally i need save this with excel type data.

回答 (2 件)

KSSV
KSSV 2022 年 7 月 6 日
a = rand(336,5) ; % random data for demo
[r,c] = size(a);
nlay = 3;
b = permute(reshape(a',[c,r/nlay,nlay]),[2,1,3]);
for i = 1:nlay
T = array2table(b(:,:,i)) ;
writetable(T,'myData.xls','Sheet',i)
end

Rohit Kulkarni
Rohit Kulkarni 2022 年 7 月 6 日
編集済み: Rohit Kulkarni 2022 年 7 月 6 日
Hi,
A similar question has been answered earlier.
Please refer this MATLAB answer for assigning same row name for a range of rows.
For assiging different names to columns, you can do this: if you already have a matrix and want to convert it to table:
array2table(matrix, 'VariableNames', {'Name1', 'Name2', 'Name3', 'Name4', 'Name5'})
or you can do the following if you already have the table
Table.Properties.VariableNames = ["Name1", "Name2", "Name3", "Name4", "Name5"]
Refer the documentation here.
"Finally i need save this with excel type data", do you want to write data to excel spreadsheet?
Use
writetable()
Refer the documentation here.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by