Can I name the variables in a table from a cell array or a struct?
古いコメントを表示
Hi!
I am loading a bunch of .txt files into Matlab and the data is stored in cell arrays (I found a tutorial that used this way).
The files contain the results of a simulation with variing parameters and there are 30 different values for each run, stored in 3 different files for each run.
After importing the files I want to copy the values from the three different files into one table (I got this to work).
Now I want to name the variables in the table and preferably with the same names as in the result files as those might be changed by the user.
Is there a way to read the names from the cell array and write it into the table without specifing it for each entry from the cell (data{1,1}, data{1,2}, ...? Or alternatively from a struct, as i managed to copy the names into a struct (name.a, name.b,...)?
Thanks!
3 件のコメント
Star Strider
2023 年 7 月 26 日
MATLAB has functions that can combine table arrays as well as name the additional variables with the names of the original table arrays. See Join Tables and the links in that page to see if one of them will do what you want.
Image Analyst
2023 年 7 月 27 日
You forgot to attach the file.
And you say they're *.txt files in your original post, but then in a comment below you say they're *.enerbal, *.enerbaltank, and *.enerballosses files. Which is it? If they're not .txt files, then zip up a few of them and attach the zip file, otherwise just attach the .txt files.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Jan Böttner
2023 年 7 月 27 日
採用された回答
その他の回答 (1 件)
Cris LaPierre
2023 年 7 月 26 日
移動済み: Cris LaPierre
2023 年 7 月 26 日
Use readtable to toad your files, and the header names will be used automatically as the table variable names.
data = readtable('patients.xls')
data.Height
カテゴリ
ヘルプ センター および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!