Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
John
John 2014년 3월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
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