필터 지우기
필터 지우기

Label X-axis title based on excel/csv header

조회 수: 4 (최근 30일)
noname
noname 2018년 4월 4일
답변: Akira Agata 2018년 4월 11일
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