Effacer les filtres
Effacer les filtres

Calculating and extracting data from three dimensional array

5 vues (au cours des 30 derniers jours)
Michael
Michael le 1 Déc 2011
Well I need to find the following things:
1. calculate the average score for each question, using all the data.
2. Extract data for question 3 for each year and create an array that compares question 3 from year 1 and year 2.
This is what i have so far:
%Create array of first and second year data
year1 = [3,6,4,10;5,8,6,10;4,9,5,10;6,4,7,9;3,5,8,10];
year2 = [2,7,3,10;3,7,5,10;4,5,5,10;3,3,8,10;3,5,2,10];
%Create 3-D array with two pages
testdata = cat(3,year1,year2)
%Calculate average for each question for each year in array
average = mean(testdata)
I'm not sure how to calculate the average of both arrays into one, and extract column 3 (question 3) from each year into one array. I know how to extract them separately but after that i don't know how to combine them. Any help would be great!

Réponse acceptée

Sven
Sven le 1 Déc 2011
Almost there, Michael. Try this to average your two years:
average = mean(testdata,3)
This will average your testdata over the 3rd dimension. To extract the third column, just try:
average(:,3)
year1(:,3)
year2(:,3)
To extract the third column from testdata, use the following:
testdata(:,3,:)
This will result in a 3-by-1-by-2 matrix. Let us know if you were looking to do something slightly different.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by