MATLAB: Reading a Matrix with operator and Cell Array from Excel

cell arraymatrix with operatorxlsread

Hello,
I have Two questions reading the function (xlsread).
Q1) How to read a matrix that has element(s) with an operator e.g.(+).
To illustrate what I want I wrote a simple code, where I have a Matrix named M, the first element is (n+1).
I want to know if possible how to write the Matrix M in excel sheet and then read in Matlab from the excel sheet.
This is the code
% Q1) Reading Matrix with operator from excel
n=1;
for i=1:3
M=[n+1 2;3 4] % Instate of writing Matrix M here, I want to read it from excel.
n=n+1;
end
The results of the code are:
M =
2 2
3 4
M =
3 2
3 4
M =
4 2
3 4
Q2) How to read a Cell Array from Excel
Similarly I want to know if possible how to write a cell array in excel sheet and then read it in Matlab from the excel sheet.
% Q2) Reading Cell Array from excel
C={1,[2 3];1,[4 5 6]} % How to read this cell array from excel?
C{1,2} % just to view what is inside

C{2,2} % just to view what is inside
The results should be:
C =
[1] [1x2 double]
[1] [1x3 double]
ans =
2 3
ans =
4 5 6
The reason I want to read the matrix and the cell array from excel is because I am dealing with quite big matrix and cell array, and I found editing them from excel is much easier.
Thank you in-advance
Alaa

Best Answer

  1. xlsread reads the value of the cell, not the underlying functional in the cell, if there is one.
  2. An Excel spreadsheet cell is analogous to an array element in Matlab, is a single location and holds a value; it doesn't have the concept of a higher-level data abstraction of the cell array.
I suspect you'd be better served in learning to use the facilities in Matlab more effectively rather than Excel--must you actually edit large arrays manually? Why not process them with scripts/functions instead and avoid the tedium?