How do I add a 52x1 data set to 52x5 matrix.

1 view (last 30 days)
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;

Accepted Answer

Walter Roberson
Walter Roberson on 3 Nov 2015
data_matrix(:, file) = influenza_a;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!