How to write values from workspace dynamically into a table

8 visualizzazioni (ultimi 30 giorni)
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 Commenti
Rik
Rik il 21 Set 2020
Modificato: Rik il 21 Set 2020
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.

Accedi per commentare.

Risposta accettata

Steven Lord
Steven Lord il 17 Set 2020
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
  1 Commento
Marie P.
Marie P. il 21 Set 2020
Thanks for the answer but this is not exactly what I wanted to do. And it sounds really complicated.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by