필터 지우기
필터 지우기

Changing the format of mat file

조회 수: 7 (최근 30일)
Khan Muhammad Adeel Khan
Khan Muhammad Adeel Khan 2020년 7월 15일
댓글: Walter Roberson 2020년 7월 15일
How to change the format of the mat file ? My data is in form of : epoch *data point *channel. I want to change the format as : channel* data point* epoch

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 7월 15일
If you have a 3D matrix, you can use the function permute to move the dimensions.
edc = rand([3 4 5]);
cde = permute(edc,[3 2 1]);
% this will make the 3rd dimension the first dimension and first dimension the third.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 7월 15일
Note that this works on a variable. You had asked to convert a file; the framework I gave goes through the file and converts all of the variables in it and creates a new file with the result.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 15일
outdir = 'swapped'; %can be fully qualified
filename = 'YourFile.mat'; %can be fully qualified
if ~exist(outdir, 'dir'); mkdir(outdir); end
ds = load(filename);
fn = fieldnames(ds);
nf = length(fn);
all_3d = true;
for K = 1 : nf
thisfield = fn{k};
thisdata = ds.(thisfield);
if ndims(thisdata) ~= 3
fprintf('variable "%s" is not 3D, quitting!\n', thisfield);
all_3d = false;
break;
end
end
if all_3d
nf = struct();
for K = 1 : nf
thisfield = fn{k};
thisdata = ds.(thisfield);
newdata = permute(thisdata, [3 2 1]);
nf.(thisfield) = newdata;
end
[filedir, basename, ext] = fileparts(filename);
newname = fullfile(outdir, [basename ext]);
save(newname, '-struct'. 'nf')
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by