How to Split a 50000x2 data in .mat into 100 equal-sized 500x2 data?

Dear community,
I am trying to split a 50000x2 data in .mat into 100 equal-sized 500x2 data (that will allow me to plot 100 figures afterwards)
Wish to get help from you all.
Thank you.

 Accepted Answer

This code shows an example of how it can be done
M = rand(50000,2);
C = mat2cell(M, 500*ones(100,1), 2);
figure()
for i = 1:numel(C)
subplot(10,10,i)
plot(C{i}(:,1), C{i}(:,2))
end

8 Comments

but my data is from .mat, how could I match it?
I created M matrix using random data. Load your .mat file and replace M in my code with the name of your variable. Remember to delete the line
M = rand(50000,2);
could I make it as below?
M = load('abc.mat')
This will not work. What is the name of variable inside 'abc.mat'? Can you attach the file here?
For example, if name of variable inside 'abc.mat' is 'X', you can use
M = load('abc.mat');
M = M.X;
You may check in the .mat file below.
inside, there are Charge and Phase.
Try this code
data = load('Trans_CoronaPDdata.mat');
M = [data.Charge data.Phase];
C = mat2cell(M, 500*ones(100,1), 2);
figure()
for i = 1:numel(C)
subplot(10,10,i)
plot(C{i}(:,1), C{i}(:,2))
end

Sign in to comment.

More Answers (1)

One way is to use mat2tiles. For example
A=rand(50000,2);
Asplit=mat2tiles(A,[500,2]);
whos A Asplit
Name Size Bytes Class Attributes
A 50000x2 800000 double
Asplit 100x1 811200 cell

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Asked:

on 5 Nov 2020

Answered:

on 6 Nov 2020

Community Treasure Hunt

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

Start Hunting!