How to write the output of the code to .csv format and save the file

3 次查看(过去 30 天)
place = ivc, val_a = 3.0000, close_a = 3.2806, diff_a = -0.0935, val_b = 3.0000, close_b = 2.8365, diff_b = 0.0545 X = 0.3, Y = -1.5, temp = 40
place = ivc, val_a = 3.0000, close_a = 3.1910, diff_a = -0.0637, val_b = 3.0000, close_b = 2.6977, diff_b = 0.1008 X = 0.3, Y = -1.5, temp = 150
place = ivc, val_a = 3.0000, close_a = 2.5851, diff_a = 0.1383, val_b = 3.0000, close_b = 2.9607, diff_b = 0.0131 X = 0.0, Y = -2.4, temp = 200
This is the output of my code has more than 10000 entries, but only shown 3 lines for reference. now i want it to be in this .csv format as follows
Place, ivc, ivc, ivc
repeated place, t, f, f, f
temperature, 40,150,200
X, 0.3,0.3,0.3
Y, -1.5, -1.5, -2.4
filename :: / folder / filename.csv
t test :: A_B_C: location_gif: 1, t, t, t
% Description
Place: There we enter the place
Repeated place: t - is true, just add f for all the places that you add (since there are 3 places we have 3 times f)
Temperature: is the temperature (in this example -40 150 200)
X and Y as separate variables
filename: add the path of the file
t test :: A_B_C: location_gif: 1, t, t, t,
The number of "t" s corresponding to the number of places.
So how do i write it? and also how do i link the output of the code and save it in .csv format? Kindly help

回答(1 个)

Image Analyst
Image Analyst 2020-6-6
Because of all that other stuff you want (place, temperature, etc.) I think it's best if you just use fprintf() to write all that stuff out in your complicated custom format.
  11 个评论
Ganesh Kini
Ganesh Kini 2020-6-8
Thank so much, I got the results
I need one help, thats when i have
[fid1, msg1] = fopen('file1.csv', 'wt' );
fprintf (fid1, 'Temperature \t');
fprintf('\n');
fprintf (fid1, 'Value_n \t');
fprintf('\n');
fprintf (fid1, 'Value_p\t');
for
for
for
...
fprintf (fid, '% 3.0f \ n' , temp)
fprintf (fid1, '% 1.1f\t' , vnw);
fprintf (fid1, '% 1.1f\t' , vpw);
end
end
end
I get the output
Temperature VNW VPW-40 1.8 -1.5 0 1.2 -1.8 25 1.2 -1.8 60 1.2 -1.5 -40 1.2 -1.8 0 1.8 -1.2 25 0.9 -1.8 60 0.9 -1.8 -40 0.9 -1.8 0 0.9 -1.8 25 0.9 -1.8 60 0.9-1.5
in a single line, but I should get the values in 3 different lines
Temperature 40,0,25 and so on ----------
Value_n 1.8, 1.2,1.2 and so on ----------
Value_p -1.5,-1.8, -1.8 and so on ----------
How do I assign each Temperature values to only temperature, Value_n to VNW and Value_p to VPW ? please help

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by