Concatenation of multiple variables into one variable
조회 수: 8(최근 30일)
표시 이전 댓글
I do have multiple variables in .mat file. Size of each variable is 1x33376. I need to concatenate all the variables into one variable, Then exclude the NaN values and find the mean of all values vertically.
댓글 수: 0
답변(2개)
Michael Haderlein
2015년 5월 6일
Assuming that the mat file contains only these variables:
data=cell2mat(struct2cell(load('filename.mat')));
meanvals=nanmean(data);
댓글 수: 2
Michael Haderlein
2015년 5월 6일
Now, should the variables be concatenated or do you want the mean for every variable? nanmean will ignore NaN, so something like
nanmean([nan 1 2;3 nan 4])
will return [3 1 3].
If you want the mean of every single variable, then you want the mean of the second dimension, right (as the size in first dimension is 1, mean does not make too much sense). So if you want the mean for each variable, just use
meanvals=nanmean(data,2);
참고 항목
범주
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!