Label X-axis title based on excel/csv header

4 次查看(过去 30 天)
I'd like to know if there is a way to label the x-axis based on the excel/csv header. I have multiple csv file,and I want to label them once I boxplot the selected file. I don't want to do it manually by using xtick since each file has different length of header. Can anyone help me with this? I really appreciate your help. Thanks!!!
(Here is my function, everything work fine, but I don't want to have 1,2,3,4 label in x-axis. Please help!!)
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
data = csvread(fullFileName,2,0);
boxplot(data);
title(baseFileName);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);

回答(1 个)

Akira Agata
Akira Agata 2018-4-11
By using readtable function, you can read header line in your csv file and put them to the figure. The following is an example.
[fileName, pathName] = uigetfile('*.csv', 'Select a file');
if fileName == 0
return;
end
fullFileName = fullfile(pathName, fileName)
data = readtable(fullFileName);
boxplot(data{:,:},'Labels',data.Properties.VariableNames);
title(fileName);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by