Names on x-axis in the excel file

5 ビュー (過去 30 日間)
muhammad choudhry
muhammad choudhry 2022 年 9 月 13 日
コメント済み: muhammad choudhry 2022 年 9 月 13 日
Hi,
I am having trouble in plotting, I want to plot the graph where x-axis are names and y-axis numbers but I am getting the error below. what is solution for that.
Code:
close all; clear all; clc;
file = ["C:\Users\Alphagamma\alphagamma.xlsx];
for i = 1:numel(file)
a=readtable(file(i));
names = a{:,3}
values = a{:,5}
end
figure()
plot (names,values)
Error:
>> figure()
plot (names,values)
Error using plot
Invalid data argument.
  2 件のコメント
Ankit
Ankit 2022 年 9 月 13 日
You can only plot numeric data. But x label you can change with the help of xTickLabels
set(gca, 'xTickLabels', XlabelStr);
muhammad choudhry
muhammad choudhry 2022 年 9 月 13 日
編集済み: muhammad choudhry 2022 年 9 月 13 日
Hi,
what am I doing wrong here I added the piece of code you mentioned!
is there no way it will read the names from the excel ?
Code:
set(gca, 'xTickLabels', names);
figure()
plot (names,values)
Error:
plot (names,values)
Error using plot
Invalid data argument.

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 13 日
plot( categorical(names), values)
  1 件のコメント
muhammad choudhry
muhammad choudhry 2022 年 9 月 13 日
that's it, sweet short and simple! Thanks alot.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by