필터 지우기
필터 지우기

How to import data from excel file as structure into Matlab?

조회 수: 35 (최근 30일)
Jannis Holtkoetter
Jannis Holtkoetter 2020년 10월 29일
편집: Walter Roberson 2022년 4월 19일
Hello, I have a relatively straight forward problem:
I have an excel sheet with two columns. The first column contains names and the second column contains numeric values. How can I import this file as a struct, so that I can access the values simply by their name?
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 10월 29일
Are the values all the same datatype such as all numeric scalars?
Jannis Holtkoetter
Jannis Holtkoetter 2020년 10월 30일
Yes the values are all numeric scalars

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 30일
T = readtable(TheFileName);
TC = table2cell(T);
TS = cell2struct(TC(:,2), TC(:,1), 1);
TS will now be a cell with field names according to the first column of the file and numeric value according to the second column of the file.
  댓글 수: 4
vishal kulkarni
vishal kulkarni 2022년 4월 19일
If column has special charcater in it, it fails.
Like,
Param1.Field1 -> this will fail
Walter Roberson
Walter Roberson 2022년 4월 19일
편집: Walter Roberson 2022년 4월 19일
User indicated that the second columns are all numeric scalars.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by