i have to get similar output as i have uploaded.why my data is getting repeated again and again?
조회 수: 1 (최근 30일)
이전 댓글 표시
T=readtable('input.csv');
th=[0:1:3]';
for i= 1:size(th)
reph=T{i,end-1};
imth=T{i,end};
result(i)=reph+1i*imth;
end
result_data=result';
for j=1:nume1(th)
result_data2(:,j)=result_data;
end
data1=[th result_data2];
csvwrite('sample.csv',data1);
my same data is getting repeated again and again
I have read input.csv file
and output should be saved in .csv format and it should exactly look similar to file plot.csv ..
2021a version
댓글 수: 0
답변 (2개)
David Hill
2022년 10월 10일
T=readtable('input.csv');
th=[0:1:3]';
result=[th,reshape(T.re+T.im*1i,size(th,1),[])];
csvwrite('sample.csv',result);
댓글 수: 3
dpb
2022년 10월 10일
Above does so with the one small task left for you to add the first row into the result cell array before calling writecell.
Only thing I'd suggest to change to generalize would be to replace the hardcoded line
th=[0:1:3]';
with
th=unique(T.Th);
to make the code more general if/when the number of elements in Th changes.
dpb
2022년 10월 10일
tT=readtable(websave('input.csv','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1151360/input.csv'));
u=unique(tT.Th); % in case number changes in future, be general
tT.C=complex(tT.re,tT.im); % convenience of short v name
out=[{'Th'} compose('p=%d',u.')]; % the header row for starters
out=[out;num2cell(u) num2cell(reshape(tT.C,numel(u),[]))]; % finish off the output cell array
writecell(out,'plot.csv') % and save
type plot.csv
댓글 수: 3
dpb
2022년 10월 11일
So, if you work thru each line at command line and see what does and refer back to the doc for any function with which you're not familiar, what, specifically do you not understand/don't follow after seeing its result?
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!