How to write values from workspace dynamically into a table

4 visualizaciones (últimos 30 días)
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 comentarios
Rik
Rik el 21 de Sept. de 2020
Editada: Rik el 21 de Sept. de 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.
Rena Berman
Rena Berman el 8 de Oct. de 2020
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by