MATLAB: Import excel sheet, multiply each column with a variable, and save the results as a new cell array

cell arraysexcelimporting excel data

Hi everyone,
I am new to Matlab coding, and would be great if some one could help me out to solve my issue.
I have an excel sheet with multiple data columns; as an example, I have first set of data as 3 columns of 1, the second set of data as 3 columns of 2, and the third set of data as 3 columns of 3. The number of rows in each data set is not equal.
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
1 1 1 3 3 3
3 3 3
I would like to multiply the first column in data set1 with 2, then multiply second column of data set1 by 3, and the third coumn of data set1 by 4. Then I would like to repeat this for dataset2 and dataset3.
The expected output;
2 3 4 4 6 8 6 9 12
2 3 4 4 6 8 6 9 12
2 3 4 4 6 8 6 9 12
2 3 4 6 9 12
6 9 12
Then I would like to save this as a cell array;
where the first 3 columns (dataset1) is to be saved as cell1, and second 3 sets of columns to be saved as cell2, and last 3 columns to be saved as cell3.
in this format;
tracks = cell(3, 1);
Would be great if someone could help me with this! I am so new to excel imports and cell arrays…
Thanks a lot!
Sara

Best Answer

The following solution is inefficient but works for R2016b and later. See Guillaume's answer for better solutions, also including one for earlier release
data=xlsread('filename.xlsx');
data2 = nan(size(data));
for i=1:size(data,2)/3
data2(:,(i*3)-2:i*3)=data(:,(i*3)-2:i*3).*[2 3 4];
tracks{i}=data2(:,(i*3)-2:i*3)
end