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!