How to write values from workspace dynamically into a table

3 vues (au cours des 30 derniers jours)
Marie P.
Marie P. le 17 Sep 2020
Commenté : Rena Berman le 8 Oct 2020
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 commentaires
Rik
Rik le 21 Sep 2020
Modifié(e) : Rik le 21 Sep 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 le 8 Oct 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by