How do I add a 52x1 data set to 52x5 matrix.
1 view (last 30 days)
Show older comments
Hunter Ducharme
on 3 Nov 2015
Answered: Walter Roberson
on 3 Nov 2015
I have a set of data (influenza_a) that I am trying to add to a data matrix (data_matrix):
data_matrix = zeros(52, 5);
influenza_a = data{:, 6} + data{:, 8};
data_matrix{ :, i } = influenza_a;
However, it returns the error:
Cell contents assignment to a non-cell array object.
So how do I add the values of influenza_a to a column in the data_matrix?
Here is my full code:
directory = ('/ParentDirectory/Data/');
csvfiles = dir(fullfile(directory,'*.csv'));
data_matrix = zeros(52, 5);
iter = 0;
for file = 1:numel(csvfiles)
iter = iter + 1;
delimiter = ',';
startRow = 2;
formatSpec = '%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
filename = fullfile(directory, csvfiles(file).name);
fileID = fopen(filename,'r');
if fileID < 0
error('Failed to open file %s', filename);
end
data = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
influenza_a = data{:, 6} + data{:, 8};
data_matrix{:, file} = influenza_a;
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Data Import and Management 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!