Label X-axis title based on excel/csv header
조회 수: 2 (최근 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);
댓글 수: 0
답변 (1개)
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!