Creating Array Struct From excel file
显示 更早的评论
I am trying to create an appropriate array from an excel sheet. I have read the sheet with [num str]=xlsread('Book1.xlsx'); This creates Name Size Bytes Class Attributes
num 5x10 400 double
and
Name Size Bytes Class Attributes
str 6x10 6920 cell
I would like to create a struct such that the field names coming from the row headers of str. but if i try
B=struct(str(1,1),num(:,1))
I get an error
Error using struct
Field names must be strings.
Please suggest a work around if you know of one. Thank you
采纳的回答
更多回答(1 个)
David Sanchez
2013-7-10
field_name = 'field_to_be';
myStruct.(field_name) = 4;
>> myStruct
myStruct =
field_to_be2: 4
3 个评论
David Sanchez
2013-7-10
Try the above with your cell-names. Do not mind about the "2" in the:
field_to_be2: 4
it's been a mistake will copying from my command window
Jan
2013-7-10
@David: Instead of explaining, that we should ignore the "2", you can simply edit your question and delete it.
Samadrita
2013-7-10
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!