How to plot a text data column from an excel file in MATLAB?
Mostra commenti meno recenti
Hello, I have imported in Matlab an excel file that contains two columns, one with numeric values, and the other one with text values. The first 5 rows can be seen below:
ABF-E 0.34
HJK-D -0.54
GHKL-I 1.34
FPLO-5 2.3
KKJLL-T 0.98
I need to plot the numeric column on the Y axis and the text column on the X axis. I can easily work with the numeric column using xlsread and plot, but I can not manage plotting the text column. How could I do it?.
I have written the following code, but I don't know what to do for the x Axis:
filename = 'MyData.xlsx';
Sheet = 2
xlRange = 'B1:B60';
Yaxis = xlsread (filename,Sheet,xlRange);
Xaxis = ????????;
plot(xAxis,Yaxis)
I would be very grateful if somebody could help me.
2 Commenti
Image Analyst
il 6 Dic 2013
What does it mean to "plot" a column of text???
Sarah
il 6 Dic 2013
Risposte (2)
sixwwwwww
il 6 Dic 2013
you can do it as follows:
[num, txt, raw] = xlsread('filename.xlsx', 1);
plot(num)
set(gca,'Xtick',1:numel(num),'XTickLabel',txt)
The last line of the code set the labels for data given in first column of your excel sheet
4 Commenti
Azzi Abdelmalek
il 6 Dic 2013
Modificato: Azzi Abdelmalek
il 6 Dic 2013
If numel(num) is big, XTickLabel will be a problem
sixwwwwww
il 6 Dic 2013
Yes but it is the only way around to get this. Also there will be a problem if the first column will also contain number and then they will be in the 'num' variable not 'txt'. But still this method can work for small number of data points and correct data format in excel
Sarah
il 6 Dic 2013
sixwwwwww
il 6 Dic 2013
here is the code for plotting both x and y values on x-axis and y-axis respectively:
[num, txt, raw] = xlsread('filename.xlsx', 1);
plot(num)
num = sort(num);
for i = 1:numel(num)
NumCell(i) = {num2str(num(i))};
end
set(gca,'Xtick',1:numel(num),'XTickLabel',txt, 'Ytick', num,'YTickLabel',NumCell)
Azzi Abdelmalek
il 6 Dic 2013
Thre is no x-axis data in your Excell file
Yaxis = xlsread (filename,Sheet);
plot(Yaxis)
5 Commenti
Sarah
il 6 Dic 2013
Azzi Abdelmalek
il 6 Dic 2013
What is the size of your data?
Sarah
il 6 Dic 2013
Azzi Abdelmalek
il 6 Dic 2013
Where will you put 60 worsds like ABF-E in X-axis?
Sarah
il 7 Dic 2013
Categorie
Scopri di più su Spreadsheets in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
