Plot text (x axis) vs. y axis (numbers)
18 views (last 30 days)
Hello I am trying to plot a set of data in which the x-axis is text and the y-axis is numbers. My y-axis is a set of 9504 numbers and my x-axis is a set of strings that start at 00H-23H then start repeating again at 00H. I want to plot this x-axis for my y-axis, that is for the 9504 numbers that I have.
y = [array of 9504 numbers]
x = [array of 9504 strings that start at 00H then 01H, and so on] when it reaches 23H it starts again at 00H.
Any help would be appreaciated.
Walter Roberson on 5 Aug 2019
Convert the strings into hours relative to the beginning, and divide by 24 so you have fractions of days. Now use those as the x axis and use datetick to choose to output hour of the day.
Alternatively you can use datetime objects and set their Format property as appropriate. duration objects might perhaps be more natural but they are weaker on arbitrary format.
TADA on 5 Aug 2019
Why don't you convert x to a number?
% mock data
hrs = arrayfun(@(n) [num2str(n) 'H'], 0:23, 'UniformOutput', false);
hrs(1:10) = strcat('0', hrs(1:10));
x = repmat(hrs, 1, 396);
y = randi(100, 1, 9504);
% convert hours string to number
xn = cellfun(@(hstr) str2double(hstr(1:2)), x);