Label X-axis title based on excel/csv header

13 visualizaciones (últimos 30 días)
noname
noname el 4 de Abr. de 2018
Respondida: Akira Agata el 11 de Abr. de 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);

Respuestas (1)

Akira Agata
Akira Agata el 11 de Abr. de 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);

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by