Clear Filters
Clear Filters

what does this line of code mean,

1 view (last 30 days)
C{k} = xlsread(name)
the main program is this:
C = cell(1,9);
for k = 1:9
name = sprintf('%04i.csv',k);
C{k} = xlsread(name);
end
A = cat(3,C{:});
what I need is to have each file conserved as a matrix so that I will have access to it whenever I need it, in addition, i will be needing to have a histogram of each file

Accepted Answer

Stephen23
Stephen23 on 20 Sep 2017
Edited: Stephen23 on 20 Sep 2017
The line of code
C{k} = xlsread(name)
reads the file with filename name, and puts any numeric data into the k-th cell of cell array C. You can learn about cell arrays by reading the MATLAB documentation:
A cell array is just a container for holding some other data, and it does not matter what that other data is. In this case it holds the numeric array that is read from the file.
  3 Comments
Stephen23
Stephen23 on 20 Sep 2017
It is quite possible that they are not the same. It could easily be that the order of files is different to what you expect, or their location is not what you expect, or that xlsread is not importing that data as you expect it to. Your job is to learn how to debug code.
You should start to investigate by looking at the files, at their location: what folder are the files in? Find the name of the file that that you say is not imported correctly, and import it yourself into a variable: how does it look?
Have you read the xlsread documentation? Does it match with your data? Excel does do strange things with numeric data sometimes, especially when it thinks that they are dates, so you should check that too. It may be that xlsread is entirely the wrong tool to use, so you might like to investigate using another tool, such as csvread (as I wrote in my original answer).
fatima-zahra achbah
fatima-zahra achbah on 20 Sep 2017
Ah I see, ok I will try other tools, the csvread does not work with me there is always a problem with it; but since I know now the general structure it will be more simple. Thanks again for the information

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!