Reformatting one column array into multiple columns

조회 수: 14 (최근 30일)
Megan Henriksen
Megan Henriksen 2018년 10월 15일
편집: Stephan 2018년 10월 15일
Hi there, I have data in a single column that I want to break into an array with 4 columns so that I can average those 4 values in each row. So lets say I have the array: [[1],[2],[3],[4],[5],[6],[7],[8]]. I want to reformat it to be [[1,2,3,4],[5,6,7,8]]. I think I can use a for loop for this, but I am unfamiliar with the formatting of the range that I need to use. Can anyone help?

답변 (1개)

Stephan
Stephan 2018년 10월 15일
편집: Stephan 2018년 10월 15일
Hi,
try:
A = [1;2;3;4;5;6;7;8]
% rearrange A to 4 columns
B = (reshape(A',4,[]))'
% get average for every row
avg = mean(B,2)
Best regards
Stephan

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by