Domanda

How would you plot an A vs B graph,where A and B are columns in Excel such as

A   
Red
Green
Blue

and

B
1:00 AM
2:00 AM
3:00 AM

for 3*3 graphs I use

set(gca,'XTick',1:3);
set(gca,'XTickLabel',{'Red','Green','Blue'});
set(gca,'YTick',1:3);
set(gca,'YTickLabel',{'1:00 AM','2:00 AM','3:00 AM'});

However manual entering for 1000*1000 would be a mess.

So my question is: How do I convert values Red Green Blue from column A as {'Red','Green','Blue'}? (in order to use them in set(gca,'XTickLabel'...)

I tried using

 color = xlsread(fileName, 'A1:A3');

but it didn't convert the data into the right format.

Any help is appreciated.

È stato utile?

Soluzione

The second output argument of xlsread contains text data. The first contains only numerical:

>> [nums,colors,raw] = xlsread('colorData.xlsx','A1:A3');
>> colors
colors = 
    'Red'
    'Green'
    'Blue'

UPDATE: The times read by xlsread are in Excel's serial date format (a numerical representation). They can be converted to a string with the time using datestr.

>> nums
nums =
    0.0417
    0.0833
    0.1250
>> datestr(nums)
ans =
 1:00 AM
 2:00 AM
 3:00 AM

These are actually dates, using Jan. 1 1900 as time zero. So, but giving just a time, it a number assuming this day. However, MATLAB uses Jan-1-0000, so if you have dates as well as times, convert them using datestr(t + datenum('30-Dec-1899')), where t is the numerical value with the serial date number.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top