0

I have come code that is held in a cell array which I wish to print to a csv file.

TC(:,1) = T(:,2); %Dates
TC(:,2) = T2(:,7); %PreClosePrice
TC{1,2}{1}={'PreClosePrice'};
TC(:,3) = T2(:,6); %PreSettlementPrice
TC{1,3}{1}={'PreSettlementPrice'};
TC(:,4) = T2(:,8); %PreOpenInterest
TC{1,4}{1}={'PreOpenInterest'};
TC(:,5:6) = T2(:,17:18); %Lower/Upper Limit Price
TC{1,5}{1}={'Lower Limit Price'};
TC{1,6}{1}={'Upper Limit Price'};
TC(:,7) = T2(:,9); %Open Price
TC{1,7}{1}={'Open Price'};
TC(:,8:9) = T2(:,10:11); %Highest/Lowest
TC{1,8}{1}={'Highest Price'};
TC{1,9}{1}={'Lowest Price'};
TC(:,10:33) = T(:,5:28); %Remainder of L2 data

 fid = fopen('TC.csv','wt');
if fid>0

   for k = 1:size(TC{1},1)

       fprintf(fid,'%s\n',[TC{1}{k}]);

   end

end

The code above allows me to write the TC(:,1) to the csv file but I can't seem to write the rest?

Can someone show me how to correct this so that I can write all the data to the csv file?

Thanks

Baz

1
  • 1
    Baz, it's not really possible to answer this with certainty without knowing exactly the structure of TC (or T and T2). However, it seems to me that if you have a cell array of several rows of cells, (e.g. say 100) and 33 columns of cells, then TC{1,2}{1} probably doesn't do what you want it to. Also your for loop should probably be going down the rows, rather than inside the cell? But like I said, it depends on what TC actually is, can't really help having no idea what TC is like. Commented Sep 21, 2016 at 19:59

1 Answer 1

1

Use an already working code. cell2csv https://www.mathworks.com/matlabcentral/fileexchange/4400-cell-array-to-csv-file--cell2csv-m-

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.