1
votes

I have imported a lot of data from an excel spreadsheet so that I have a 1x27 matrix.

I have imported data from excel using this

filename = 'for_matlab.xlsx';
sheet = 27;
xlRange = 'A1:G6';
all_data = {};

for i=1:sheet,
    all_data{i} = xlsread(filename, i, xlRange);
end

However each element of this all_data matrix (which is 1x27) contains my data but I'm having trouble accessing individual elements.

i.e.

all_data{1} 

Will give me the entire matrix but I need to perform multiplications on individual elements of this data

also

all_data(1)

just gives '5x6 double', i.e. the matrix dimensions.

Does anybody know how I can divide all elements of each row by the third element in each row and do this for all of my 'sub-matrices' (for want of a better word)

3
It's not clear what format your data are in. Perhaps you can make a small mock data set and post some code to receate it e.g. {{[1 2; 3 4], [5, 6; 7, 8]}, {[1 2; 3 4], [5, 6; 7, 8]}}. Just make sure to try include all features such as if matrices sizes can differ etcDan

3 Answers

2
votes

Assuming that all_data is a cell array and that each cell contains a matrix (with at least three columns):

result = cellfun(@(x) bsxfun(@rdivide, x, x(:,3)), all_data, 'uniformoutput', 0);
2
votes

You are mixing terminology in matlab. what you have is 1x27 CELLS each of them containing a matrix. If you access all_data{1} it will give you the whole matrix stored in the first cell. If you want to access the elemets of that matrix then you need to do: all_data{1}(2,4). This example access the 2,4 element of the matrix in the first cell.

Definitely Luis Mendo has solved you problem, but be aware of the differences of Cells and matrixes in Matlab!

0
votes

Okay I have found the answer now.

Basically you have to use both types of brackets because the data types are different

i.e. all_data{1}(1:4) or something like that anyway.

Cheers