필터 지우기
필터 지우기

Calculating and extracting data from three dimensional array

조회 수: 5 (최근 30일)
Michael
Michael 2011년 12월 1일
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!

채택된 답변

Sven
Sven 2011년 12월 1일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by