hi all, I have two column in excel I want to plot them by using matlab, lets say I have first column from A1-A10 and second column from B1-B10. how could I plot them in MATLAB ?? please help..

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 14 Juil 2012

7 votes

[v,T,vT]=xlsread('name.xls')
% 'xlsx' for exell 2007
%v: Double
%T and vT : cell
%use v containing numbers
t=v(:,1);y=v(:,2)
%if u have to plot second colone depending on first:
plot(t,y)

11 commentaires

Samer Husam
Samer Husam le 16 Juil 2012
I am getting an error once I use this code :
num=xlsread('name.xls','Sheet1');
x = num(6:16, 1); %start plotting from A6 until A16
y = num(6:16, 4); %start plotting from D6 until D16
plot(x,y)
error is saying : ??? Index exceeds matrix dimensions.
why I am having this error ????
Azzi Abdelmalek
Azzi Abdelmalek le 16 Juil 2012
Modifié(e) : Azzi Abdelmalek le 16 Juil 2012
don't use num=xlsread('name.xls','Sheet1'); use
[num,T,vT]=xlsread('name.xls','Sheet1');
x = num(:, 1);
y = num(:, 4);
Samer Husam
Samer Husam le 17 Juil 2012
thanks Azzi for your answer, its works, but I can't set the first cell to A6, once I set it from A6-A16 will be an error, but in this way num(:, 1) wouldn't be an error.. how to overcome this ?
The only difference between the one-output version of xlsread() and the three-output version is that you get the two extra outputs. If you do not need them, do not bother outputting them.
[num,txt,raw] = xlsread(filename) reads data from the first worksheet in the Microsoft Excel spreadsheet file named filename and returns the numeric data in array num. Optionally, returns the text fields in cell array txt, and the unprocessed data (numbers and text) in cell array raw.
Notice how txt and raw are considered optional outputs, and how num is always a numeric array and not a cell array.
Azzi Abdelmalek
Azzi Abdelmalek le 17 Juil 2012
Modifié(e) : Azzi Abdelmalek le 17 Juil 2012
ok you are right Walter, i don't know why i thought that num=xlsread(.) was a cell format, maby on the previous matlab.
Azzi Abdelmalek
Azzi Abdelmalek le 17 Juil 2012
Samer, your data are from A1 to A10, i dont understand, what youu mean by setting them from A6 to A16. if you mean that you want to move your cell from A1 to A6 in excell file, that doesn't change anything, the result will be the same
Samer Husam
Samer Husam le 18 Juil 2012
Walter, thanks for this brief about xlsread its very useful.
Azzi, I have two files to plot in excel, the first is from (A1-A10) and its done based on ur help and other engineers suggestions. but the second one is start plotting from A6-A16 that part I am not able to do it. so that I am asking for your help.
Azzi Abdelmalek
Azzi Abdelmalek le 18 Juil 2012
Modifié(e) : Azzi Abdelmalek le 18 Juil 2012
the question is have you problems to import data to plot them. anyway use num=xlsread('file2.xls'). check your matrix num ; tell us what u 've got? what kind of error message?
Samer Husam
Samer Husam le 18 Juil 2012
when its start plotting its gets an error, the error said:
??? Index exceeds matrix dimensions. why i am getting this kind of error ??
Azzi Abdelmalek
Azzi Abdelmalek le 18 Juil 2012
maby you are ploting num(6:16,1) wich is false,you must use num(:,1)) for the first row and num(:,2) for the second. i don't think you will have an error message
Samer Husam
Samer Husam le 20 Juil 2012
thanks a lot Azzi, walter and image analyst for your help... this is the correct answer, another request how to show the value of the cell if I have time value in my excel file ?? like the excel value is 12.30 ?? how to put in the graph ?

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 14 Juil 2012
Modifié(e) : Image Analyst le 14 Juil 2012

0 votes

Use xlsread() to get the entire contents of your workbook into a cell array.
[num,txt,raw] = xlsread(filename); % From the help
Then use cell2mat or something to extract out columns into an x array and a y array.
x = cell2mat(num(1:10, 1)); % Untested
y = cell2mat(num(1:10, 2)); % Untested
Then, to plot, use
plot(x,y);

9 commentaires

Samer Husam
Samer Husam le 14 Juil 2012
thanks for your suggestion, but there is an error why plotting the graph... its occurring because of cell2mat, is there any other way ?
The array "num" that is returned by xlsread() is a numeric array instead of a cell array.
x = num(1:10,1);
y = num(1:10,2);
plot(x,y)
Samer Husam
Samer Husam le 14 Juil 2012
its shows this error:
Index exceeds matrix dimensions.
Samer Husam
Samer Husam le 14 Juil 2012
I am getting this error because I am trying to read from A6 and B6, how can I define it according to your method ??
can you please define the variables ? like, it is :
num(first cell: last cell,column number)
is this your arranging ?
The letters correspond to column numbers, which are the second coordinate. The numbers correspond to rows, which are the first coordinate.
A6 = num(6,1);
B6 = num(6,2);
Samer Husam
Samer Husam le 14 Juil 2012
thanks Walter for explaining. but why I am getting this error ??
??? Index exceeds matrix dimensions.
Azzi Abdelmalek
Azzi Abdelmalek le 14 Juil 2012
num is double, u have not to use cell2mat
Walter Roberson
Walter Roberson le 17 Juil 2012
What does size(num) show? And please show your xlsread() command so we are sure we are talking about the same options.
andhavarapu lokesh
andhavarapu lokesh le 6 Mar 2017
I wanted to plot a excel sheet in matlab is there any method to scale the xaxis and yaxis commonly to all the sheets

Connectez-vous pour commenter.

arif hussain
arif hussain le 14 Mai 2017

0 votes

Hello; Can someone please help me matlab doesn't plot my excel data it show the axis only.i have attested the excel file as well.

4 commentaires

Walter Roberson
Walter Roberson le 14 Mai 2017
What is your current code?
Which MATLAB version are you using?
Image Analyst
Image Analyst le 14 Mai 2017
What does "attested" mean in this context?
dpb
dpb le 15 Mai 2017
Almost certainly a spellcheck miss from a non-English speaker attempting "attached".
Image Analyst
Image Analyst le 15 Mai 2017
I guess that makes sense, instead of "verified". However the file was NOT attached - only a screenshot was displayed, no Excel file was attached. Use the paperclip icon.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by