Setting X-Axis with Text Labels

8 ビュー (過去 30 日間)
Sai Gudlur
Sai Gudlur 2020 年 5 月 20 日
コメント済み: Sai Gudlur 2020 年 5 月 20 日
My question is related to the code pasted.
In line 4 of the code Variable "Tools" has the string of Text that is extracted from the excel file but to set it as x-lables i had to list them out again. Could someone suggest me solution where i can use the variable with strings in my code to be used as lables and not individually listing them out.
Thanks
Sai
[filename,pathname] = uigetfile("*.xlsx");
A = fullfile(pathname,filename);
num = importdata(A);
Tools = num.textdata(3:end,1);
Prices = num.data(1:6,1);
bar(Prices)
set(gca,'xticklabel',{'Table Saw','BandSaw','Jointer','Planer','Dust Collector','Calipers'});
  1 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 5 月 20 日
Are these labels present in your xlsx file?

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2020 年 5 月 20 日
編集済み: Adam Danz 2020 年 5 月 20 日
Try this. If it doesn't work, please elaborate.
set(gca,'XTick',1:6,'XTickLabel',Tools)
I assume Tools is the cell array of 6 x-tick labels.
An improvement that doesn't rely on hard-coded indices,
set(gca,'XTick',1:numel(Prices),'XTickLabel',Tools)
  1 件のコメント
Sai Gudlur
Sai Gudlur 2020 年 5 月 20 日
Thanks a lot this works. first defining 'XTick' to range as long as its Corresponding variable and using other variable with strings as its label is perfect. Thanks again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by