Effacer les filtres
Effacer les filtres

Label X-axis title based on excel/csv header

4 vues (au cours des 30 derniers jours)
noname
noname le 4 Avr 2018
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);

Réponses (1)

Akira Agata
Akira Agata le 11 Avr 2018
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);

Community Treasure Hunt

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

Start Hunting!

Translated by