grouping values that as need
1 view (last 30 days)
Show older comments
Nicle Davidson
on 5 Nov 2021
Commented: Nicle Davidson
on 5 Nov 2021
I hava a csv file with totally random numbers all in one column, that I read from using
whoeCulomn = readtable('test2.csv');
this table have 60 values in one column,
I would like to splitt these 60 values into 10 groups in which each of these have 6 of the values. for example the frist group have from 1 ot 6 the second group have from 7 to 12 etc
How can I do that?
*the groups of my numbers should be presented such as:
x1=[the first group of six numbers]
x2=[the second group]
x3=[...];
x4=[...];
x5=[...];
x6=[...];
0 Comments
Accepted Answer
Sudharsana Iyengar
on 5 Nov 2021
Edited: Sudharsana Iyengar
on 5 Nov 2021
An example:
x=linspace(1,60,60);
k=1;
for i =1:6:length(x)
B(k,1:6)=x(i:i+5) %; add this semicolon if you dont want this to be printed.
k=k+1;
end
A = 1:60;
B = reshape(A,[10,6]) %more easier way
10 Comments
Sudharsana Iyengar
on 5 Nov 2021
May be this explanation is more clearer:
Instead of having has X1,X2...X10 you have X with 10 rows and 6 coloumns. Each row corresponds to each of X1,X2... So you can access them by calling the row index.
X(i,:) % will call the ith row and all the columns. So if i is 1 you are acessing X1 if it is 3
% you are acessing X3 and so on.
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!