Info

This question is closed. Reopen it to edit or answer.

How can i put an date array extracted from excel in a for loop?

1 view (last 30 days)
Hi!
I extracted data from excel file (first column only with dates).
I used xlsread and then DATE=TXT(3:end,1)
Now im trying to create a table where the first two rows are called 'CouponDates' and 'CashFlow, and the rest of the columns to be all the dates present in DATE.
I typed this but it doesnt work:
z=length(DATE)
E=cell(z+2,1)
for j=1:z;
E{j+2,1}=DATE(j,1);
end
Could anybody help me?
Thanks in advance

Answers (2)

Image Analyst
Image Analyst on 27 Mar 2014
Forget cell arrays - too complicated. Just read into a the new data type "table" directly with the new readtable() function:
t = readtable('myWorkbook.xlsx');
There - you now have your table. You can then do pretty much anything you want with it just like it's a regular array. It's very intuitive. Try it (requires R2013b or later).

Walter Roberson
Walter Roberson on 27 Mar 2014
Without loop:
E = {[]; []; cellstr(TXT(3:end,1)) };
With loop:
z = size(DATE,1);
E = cell(z+1,1);
for j = 1 : z
E{j+2,1) = DATE(j,:); %not just column 1
end

Tags

Community Treasure Hunt

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

Start Hunting!