how to plot string data on x axes

4 ビュー (過去 30 日間)
Muhammad
Muhammad 2021 年 5 月 29 日
コメント済み: Scott MacKenzie 2021 年 5 月 29 日
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

採用された回答

Scott MacKenzie
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 件のコメント
Muhammad
Muhammad 2021 年 5 月 29 日
now i want to sort that obtained graph in desending oder how?
Scott MacKenzie
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 ExchangeEpidemiology についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by