how to plot string data on x axes
24 次查看(过去 30 天)
显示 更早的评论
my workspace
cases 333*1 double
names 333*1 cell
names includes countries name
cases includes covid cases
i want to plot names on x axes and cases on y axes
plot(names ,cases)
>>Error using plot
Invalid first data argument
0 个评论
采纳的回答
Scott MacKenzie
2021-5-29
编辑:Scott MacKenzie
2021-5-29
% test data
cases = randi(100, 1, 5); % number of covid cases
names = { 'abc' 'def' 'ghi' 'jkl' 'mno' }; % country names
% organize data in cell array and sort
C = [num2cell(cases') names'];
C = sortrows(C, -1); % descending by number of cases
% cases on y axis, names on x axis
bar([C{:,1}]);
set(gca, 'xticklabels', C(:,2));
2 个评论
Scott MacKenzie
2021-5-29
OK, good. I've modified the code to include sorting by number of covid cases in descending order.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!