- xlsread reads the value of the cell, not the underlying functional in the cell, if there is one.
- 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.
Reading a Matrix with operator and Cell Array from Excel
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
dpb
on 22 May 2017
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?
2 Comments
dpb
on 22 May 2017
Not sure what appearance you would want; what would you envision doing with a cell array in Excel, anyway? The size of that array in the cell would take up the space defined by it leaving blank areas elsewhere and what's the point, anyway?
You can format from Matlab however want/need but if arrays are sizable it's generally true that visually inspecting them isn't practical no matter what form is chosen--there's just only so much screen real estate and one can only comprehend so many values where "so many" is a pretty small number.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!