Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

include calculated data into csv file

조회 수: 1 (최근 30일)
isamh
isamh 2020년 10월 26일
마감: MATLAB Answer Bot 2021년 8월 20일
so, I created a code that does some calculaiotns for me, i have an .xlsx file with data and my code solves for some calcautions that i need. I want to add those calctions to the xlsx file and i found a way to do that. this time, instead of a xlsx file, i have a csv file. how can i do that with the csv file?
please try to help me, im stuck
code for xslx file( i want to keep data already on file and include the calculations)
%Table
Table1 = table(Speed_50_1 , Speed_50_2 , Speed_55_1 , Speed_55_2 , Speed_60_1 , Speed_60_2 , Speed_65_1 , Speed_65_2 , Speed_70);
S = Table1{:,:};
filename = 'Tesla_Steady_State_005.xlsx';
writetable(S,filename,'Sheet',1,'Range','A1:A27')
code for csv(this add the calculations but gets rid of all the data):
Table1 = table(Speed_50_1, Speed_50_2, Speed_55_1, Speed_55_2, Speed_60_1, Speed_60_2, Speed_65_1, Speed_65_2, Speed_70);
S = Table1{:,:};
writetable(S,'Tesla_Steady_State_027.csv')
T_preserve = readtable('Tesla_Steady_State_027.csv','Delimiter',',');

답변 (1개)

Mathieu NOE
Mathieu NOE 2020년 10월 27일
hi
I think the solution already exist :
help writetable
"WriteMode" : - "append": Append to the bottom of the occupied range within the sheet.
this way you can add at he bottom of your file your new output
  댓글 수: 30
isamh
isamh 2020년 11월 2일
so something like this?
Table1 = [Speed_50_1, Speed_50_2, Speed_55_1, Speed_55_2, Speed_60_1, Speed_60_2, Speed_65_1, Speed_65_2, Speed_70];
PD = padarray(Table1,[1,0],0)
T_preserve = readtable('Tesla_Steady_State_027.csv','Delimiter',',');
T_new = [T_preserve, PD];
writetable(T_new, 'Tesla_Steady_State_027.csv');
isamh
isamh 2020년 11월 2일
%this is what i got
Error using padarray>ParseInputs
(line 131)
Function padarray expected A
(argument 1) to be numeric or
logical for constant padding.
Error in padarray (line 68)
[a, method, padSize, padVal,
direction] = ParseInputs(args{:});

태그

Community Treasure Hunt

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

Start Hunting!

Translated by