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

 Réponse acceptée

Stephen23
Stephen23 le 20 Sep 2017
Modifié(e) : Stephen23 le 20 Sep 2017

0 votes

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 commentaires

Stephen23
Stephen23 le 20 Sep 2017
fatima-zahra achbah's "Answer" moved here:
thank you for your response, the problem is whenever I compare cell 1 for example with first csv file 0001 I realize that they are not the same. C{1} for example does not give me what is in 0001 thanks in advance
Stephen23
Stephen23 le 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 le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by