Reputation: 698
I have the following code and wish to append the output to an array row by row. Each loop iteration should place the 1st date in Row 1, Column 1 and the first value of R should be placed in Row 1, Column 2. The next iteration will place additional information in the subsequent Row. The number of column entries will be predetermined but the number of Row entries will be indefinite. Please advise.
X = [41334:41340];
Y = [];
exceldate = X;
date = x2mdate(exceldate);
for i=1:1:7
curDate = datestr(date,26);
%Write curDate value to Row i, column 1 of Y
R(i) = i+1;
%Write R(i) value to Row i, column 2 of Y
end
I'm trying to make Y look like:
2013/03/01 2
2013/03/02 3
2013/03/03 4
2013/03/04 5
2013/03/05 6
2013/03/06 7
2013/03/07 8
Upvotes: 0
Views: 165
Reputation: 7448
You need to use a cell array to combine text (your date strings) and numeric values into a single array.
%# initialize sample date cell array
dates = cellfun(@datestr,{now,now+1,now+2},'UniformOutput',false)';
%# intialize sample data array
numVals = [1:3]';
%# combine
out = [dates,num2cell(numVals)];
Upvotes: 0
Reputation: 600
You need to use a cell array for this.
Y = cell(7, 2);
In the loop you can then do:
Y{i, 1} = curDate;
Y{i, 2} = R(i);
Note that you need to use curly braces to assign to positions in the cell array.
Upvotes: 1