MATLAB Answers

Writing variables in .csv file and saving it

130 views (last 30 days)
Ganesh Kini
Ganesh Kini on 6 Jun 2020
Edited: Ameer Hamza on 10 Jun 2020
Hi,
I have a functionality that works perfectly fine. But the output has a set of Numeric value and text strings.
for ex: abc, 1, def,1
def,2, rfg, 1
How can i save the output in a .csv file? do i need to put all my output values of the code to a Matrix then use csvwrite() function?
Please suggest your inputs

  0 Comments

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 6 Jun 2020
If you have R2019a or later, you can save the data in a cell array and use writecell()
C = {'abc', 1, 'def' 1; 'def', 2, 'rfg', 1};
writecell(C, 'test.txt')

  25 Comments

Ganesh Kini
Ganesh Kini on 9 Jun 2020
Hi Ameer,
Tried your method, it didn't work as expected
Temperature t 60 60 60 60 60 60 60 60 60 60 60 60
Value_n t 1 1 1 1 1 1 1 1 1 1 1 1
Value_p t -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
Could you please tell me where i can change this?
The value needs to change after one complete execution, but it is not doing that
Ganesh Kini
Ganesh Kini on 9 Jun 2020
size(backend_full)
Output
ans =
12 7
But when i write the above code for repeated values
fprintf (fid2, '\nEnable,t,');
fprintf (fid2, 'f,', ones(1,size(backend_full)));
Output on the csv file
Enable,t,f,
Please let me know
Ameer Hamza
Ameer Hamza on 10 Jun 2020
Are all the variables calculated before this line?
vars = {temp, vnw, vpw}
or are they calculated inside for-loop?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!