How to write values from workspace dynamically into a table

조회 수: 5 (최근 30일)
Marie P.
Marie P. 2020년 9월 17일
댓글: Rena Berman 2020년 10월 8일
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
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.
Rena Berman
Rena Berman 2020년 10월 8일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
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
  댓글 수: 1
Marie P.
Marie P. 2020년 9월 21일
Thanks for the answer but this is not exactly what I wanted to do. And it sounds really complicated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by