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..

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 7 月 14 日

7 投票

[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 件のコメント

Samer Husam
Samer Husam 2012 年 7 月 16 日
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 2012 年 7 月 16 日
編集済み: Azzi Abdelmalek 2012 年 7 月 16 日
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 2012 年 7 月 17 日
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 ?
Walter Roberson
Walter Roberson 2012 年 7 月 17 日
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 2012 年 7 月 17 日
編集済み: Azzi Abdelmalek 2012 年 7 月 17 日
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 2012 年 7 月 17 日
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 2012 年 7 月 18 日
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 2012 年 7 月 18 日
編集済み: Azzi Abdelmalek 2012 年 7 月 18 日
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 2012 年 7 月 18 日
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 2012 年 7 月 18 日
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 2012 年 7 月 20 日
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 ?

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2012 年 7 月 14 日
編集済み: Image Analyst 2012 年 7 月 14 日

0 投票

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 件のコメント

Samer Husam
Samer Husam 2012 年 7 月 14 日
thanks for your suggestion, but there is an error why plotting the graph... its occurring because of cell2mat, is there any other way ?
Walter Roberson
Walter Roberson 2012 年 7 月 14 日
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 2012 年 7 月 14 日
its shows this error:
Index exceeds matrix dimensions.
Samer Husam
Samer Husam 2012 年 7 月 14 日
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 ?
Walter Roberson
Walter Roberson 2012 年 7 月 14 日
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 2012 年 7 月 14 日
thanks Walter for explaining. but why I am getting this error ??
??? Index exceeds matrix dimensions.
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 7 月 14 日
num is double, u have not to use cell2mat
Walter Roberson
Walter Roberson 2012 年 7 月 17 日
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 2017 年 3 月 6 日
I wanted to plot a excel sheet in matlab is there any method to scale the xaxis and yaxis commonly to all the sheets

サインインしてコメントする。

arif hussain
arif hussain 2017 年 5 月 14 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2017 年 5 月 14 日
What is your current code?
Which MATLAB version are you using?
Image Analyst
Image Analyst 2017 年 5 月 14 日
What does "attested" mean in this context?
dpb
dpb 2017 年 5 月 15 日
Almost certainly a spellcheck miss from a non-English speaker attempting "attached".
Image Analyst
Image Analyst 2017 年 5 月 15 日
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.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by