Cant write array to csv file - Please help
2 views (last 30 days)
Show older comments
Code ---
function result = createArrays(nArrays, arraySize)
result = cell(1, nArrays);
for i = 1 : nArrays
result{i} = zeros(arraySize);
end
end
To use it:
myArray = createArrays(44, [2464,1]);
for i = 1:44
if i==1
j=1;
elseif i>1
j=CountryVar(i-1)+1;
end
for ii = 1:2464
for jj = j: CountryVar(i)
if jj<= CountryVar(i)
myArray(i) = sum(ImportsBreakdownMatrix(:,j:CountryVar(i)));
end
end
end
end
CountryVar = [56:56:2464];
and ImportsBreakdownMatrix is just 2464, 2464 matrix with numbers
The calculations work but I can write myArray in csv file.
CSV2CELL, dlmwrite have not helped.
I am trying to separate a 2464,2464 matrix into 44 matrices of 2464,1 summing 56 columns at a time which is why I used arrays.
Any help will be appreciated..
1 Comment
Walter Roberson
on 7 Feb 2018
You have a cell array with the entries being numeric row vectors (not the column vectors you initialize.) The export routines will refuse to export that in one piece to a single csv file because csv files have no ability to store groups of numbers in one csv location. Each location in a csv must be either empty, or a numeric scalar, or a string (possibly double-quoted).
Perhaps you should loop writing one cell per file ? Or perhaps you should use an excel file and create different "sheets" ?
Answers (0)
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!