What is the simplest way to load different sets of data from the same Excel file?

2 views (last 30 days)
I want to plot multiple graphs from an Excel file. However, each graph would have different sets of data from that file. This is how I set up my script:
if true
Data = xlsread('Caregivers.xlsx');
Table = xlsread('Caregivers.xlsx', 'Caregivers', 'B2:K101');
% Finding the mean, median, minimum, maximum, and standard deviation of variables
Mean = mean(Table, 1);
Median = median(Table, 1);
Minimum = min(Table);
Maximum = max(Table);
Standard_Deviation = std(Table);
% Table of mean, median, minimum, maximum, and standard deviation
Statistics = [Mean',Median', Minimum', Maximum', Standard_Deviation']
% Create a histogram for caregiver age
age = xlsread('Caregivers.xlsx', 'Caregivers', 'B2:B101');
subplot (3, 2, 1)
hist(age)
title ('Histogram for Caregiver Age')
xlabel ('Age (years)')
ylabel ('Amount of Caregivers')
% Create a histogram for caregiver income
income = xlsread('Caregivers.xlsx', 'Caregivers', 'C2:C101');
subplot(3, 2, 2)
hist(income)
title ('Histogram for Caregiver Income')
xlabel ('Income ($)')
ylabel ('Amount of Caregivers')
end
Is there a simpler way (other than writing xlsread = ... multiple times) to load these different data sets?

Answers (1)

Becca
Becca on 16 Feb 2015
Instead of using the xlsread function multiple times, you can call the column you want from your table and assign it to a variable. For example:
age = xlsread('Caregivers.xlsx', 'Caregivers', 'B2:B101') %Instead, you can type
age= Table(:,1) %because B is the first column in matrix 'Table'
end

Community Treasure Hunt

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

Start Hunting!