Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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

回答(2 个)

Image Analyst
Image Analyst 2014-3-27
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 2014-3-27
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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by