How to split .mat data into different variables?

조회 수: 7 (최근 30일)
Faheem Ur Rehman
Faheem Ur Rehman 2021년 4월 14일
댓글: Faheem Ur Rehman 2021년 4월 14일
I have .mat file in workspace which is 5120x1 dimention. I want to split that into (1024x1), (2048x1), (3072x1), (4096x1) and (5120x1) in 5 different varibales.
Is it possible with mat2cell function?
  댓글 수: 1
madhan ravi
madhan ravi 2021년 4월 14일
You haven’t told us what classes they are and haven’t shared the file either.

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

채택된 답변

Rik
Rik 2021년 4월 14일
You can't have a file in your workspace, only variables (and objects if you don't count those as variables).
There are some guesses involved in what you want. Below is my best guess.
data=rand(5120,1);%generate some random data
c=num2cell(1024:1024:5120);
for n=1:numel(c)
c{n}=data(1:c{n});
end
c
c = 1×5 cell array
{1024×1 double} {2048×1 double} {3072×1 double} {4096×1 double} {5120×1 double}
You shouldn't want to put it in seperately named variables, as that will prevent you from using indexing to get to these results. However, if you insist, you can use the deal function to split the cell.
[foo,bar,foobar,f00,barr]=deal(c{:});
foo
foo = 1024×1
0.5291 0.7418 0.5861 0.9820 0.9140 0.5865 0.2450 0.8748 0.7799 0.4680
  댓글 수: 8
Rik
Rik 2021년 4월 14일
for n=1:numel(c)
data=c{n};
filename=sprintf('data_part_%02d.mat',n);
save(filename,'data')
end
This will write the 50 mat files you appear to want.
You still haven't explained how the input to your later function works. We might be able to suggest improvements.
Faheem Ur Rehman
Faheem Ur Rehman 2021년 4월 14일
The earlier code you give me is giviing output of (1024,1) 5 times but i need (0:1024),(1025:2048)... like that.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by