필터 지우기
필터 지우기

Creating variables and assigning values from table data

조회 수: 16 (최근 30일)
Mihir Tasgaonkar
Mihir Tasgaonkar 2022년 12월 15일
답변: Stephen23 2022년 12월 15일
Hi,
I'm looking to create variables and save them in a .mat file. The issue is all the variable names are stored in an Excel file along with their values (variable name in Column A and its value in Column B). Is there any way I can create these variables directly from the table data? I have almost 1500 rows in the Excel file, so doing this manually ( like A = B(1,1)) is not a option.
Please help out.

답변 (1개)

Stephen23
Stephen23 2022년 12월 15일
"Is there any way I can create these variables directly from the table data?"
Easy, just convert the data to a structure and SAVE using the -STRUCT option. This shows you the basic idea:
C = readcell('test.csv')
C = 2×2 cell array
{'hello'} {[3.1415]} {'world'} {[ 123]}
S = cell2struct(C(:,2),C(:,1),1)
S = struct with fields:
hello: 3.1415 world: 123
save('test.mat','-struct','S')

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by