
how to plot string data on x axes
조회 수: 4 (최근 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에서 Epidemiology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!