필터 지우기
필터 지우기

Creating Array Struct From excel file

조회 수: 3 (최근 30일)
Samadrita
Samadrita 2013년 7월 10일
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

채택된 답변

Jan
Jan 2013년 7월 10일
Your str is a cell string. Then you need curly braces:
B = struct(str{1,1}, num(:,1))

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 7월 10일
field_name = 'field_to_be';
myStruct.(field_name) = 4;
>> myStruct
myStruct =
field_to_be2: 4
  댓글 수: 3
Jan
Jan 2013년 7월 10일
@David: Instead of explaining, that we should ignore the "2", you can simply edit your question and delete it.
Samadrita
Samadrita 2013년 7월 10일
I am not sure if I am following this right...Should I manually name the fields? I do need it to be read off the excel sheet. If you could please explain a bit further, I would appreciate it. Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by