How to write values from workspace dynamically into a table
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I just got started with Matlab(so if this question has already been asked but I oversaw it, just let me know!) I am playing around with a simple model that solves different x in differential equations with different parameter settings. I want to save some of the values from workspace in a table and want to write it into an individual csv. file. I have x(1), x(2) and x(3) which each gets a value for a parameter for their equation, so I give matlab a vector eg: v=[1 1 1]. I also have some parameters that determine what happens with which x and instead of writing it myself manually in the table like f= 1, so something becomes true for x(1), I want Matlab to do it for me.(I also failed at the part to write a table myself for now, by the way).
I want a table with 4 colums where the first columns contains all the variable names, 2-4 should contain x(1), x(2) and x(3) so that I can see which parameter was used for which x. when f=2, I want matlab to write a zero in the column of x(1) and x(3) and a 1 in the column for x(2).
I hope it gets clear what I want to do :(
edit: Sorry for the bad explanation, but I am not allowed to post my original code here due to its a project for university.
4 个评论
Rik
2020-9-21
编辑:Rik
2020-9-21
Why did you edit your question?
Original post:
How to write values from workspace dynamically into a table
Hello everyone, I just got started with Matlab(so if this question has already been asked but I oversaw it, just let me know!) I am playing around with a simple model that solves different x in differential equations with different parameter settings. I want to save some of the values from workspace in a table and want to write it into an individual csv. file. I have x(1), x(2) and x(3) which each gets a value for a parameter for their equation, so I give matlab a vector eg: v=[1 1 1]. I also have some parameters that determine what happens with which x and instead of writing it myself manually in the table like f= 1, so something becomes true for x(1), I want Matlab to do it for me.(I also failed at the part to write a table myself for now, by the way).
I want a table with 4 colums where the first columns contains all the variable names, 2-4 should contain x(1), x(2) and x(3) so that I can see which parameter was used for which x. when f=2, I want matlab to write a zero in the column of x(1) and x(3) and a 1 in the column for x(2).
I hope it gets clear what I want to do :(
edit: Sorry for the bad explanation, but I am not allowed to post my original code here due to its a project for university.
采纳的回答
Steven Lord
2020-9-17
Here's a small example you could use as a model:
T = array2table(magic(3)) % T is a 3-by-3
T(4, :) = {10, 11, 12} % T is now a 4-by-3
As I created it in this example, the RowNames property of T is empty. But you could set that property then use the RowNames to access and manipulate the table.
T.Properties.RowNames = ["A"; "B"; "C"; "D"]
T{"C", "Var2"} % 9
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!