MATLAB: Data transfer from excel to matlab!

importing excel data

Hello to everyone
I want data transfer from excel to matlab. You can see the matrix I want to create in the image.
matrix.PNG
For example, I want to create [1 1 1] where the matrix intersects the first row and column. How can I do that? Thanks.

Best Answer

It would be much easier to help you if attached a demo excel file so we can be sure of the actual format you're using to store the data.
Saying that, it looks like you want to store [1 1 1] in a single excel cell and get that as a matrix of numbers in matlab. That's not a good idea. On the matlab side, to store that you'll either need a cell array (if the vectors are different size) or a 3D matrix (if the vectors are all the same size). Neither can be represented easily in excel so you have to come up with a special storage scheme in excel. The one you have chosen is probably the worst one as it forces you to store the numbers as text which will impose a very slow text to number conversion.
I recommend you come up with a different way to store your data in excel, one where you store the numbers as actual numbers. For example if you want MxN cell array of 1x3 vectors, I'd recommend you store the data as in Mx(Nx3) excel range where each cell contain a single number. You can read that easily with xlsread and split into a cell array with mat2cell:
%data is store as M x (Nx3) 2D array in excel

data = xlsread('somefile.xlsx');
assert(mod(size(data, 2), 3) == 0, 'Width of array in excel is not a multiple of 3')
data = mat2cell(data, size(data, 1), ones(1, size(data, 2) / 3) * 3);
Or you could reshape into a 3d matrix:
%data is store as M x (Nx3) 2D array in excel
data = xlsread('somefile.xlsx');
assert(mod(size(data, 2), 3) == 0, 'Width of array in excel is not a multiple of 3')
data = permute(reshape(data, size(data, 1), 3, []), [1 3 2]); %create a MxNx3 array