in R2023a, A text file, containing huge data in one column,How arrange data in 6 colum.where The first six number at the first Row and second six number in second Row.

1 view (last 30 days)
in R2023a, A text file, containing huge data in one column,How arrange data in 6 colum.where The first six number at the first Row and second six number in second Row.....

Accepted Answer

Stephen23
Stephen23 on 3 May 2023
F = 'the name fo your file';
M = readmatrix(F);
M = reshape(M,6,[]).'

More Answers (1)

Mathieu NOE
Mathieu NOE on 3 May 2023
hello
to load your text file use readmatrix
then you can use this demo code below to shape the data in 6 columns
as the data length may not be an exact multiple of 6 here I padded the data (28 values) with zeroes at the end to have at the end 30 samples (5 rows). You may want another value or NaN if you prefer
a = (1:28)' % dummy data vector (column)
a = 28×1
1 2 3 4 5 6 7 8 9 10
cols = 6; % how many columns ?
%% main code
samples = numel(a);
rows = ceil(samples/cols); % compute how many rows are needed
% padd data to fill all rows
tmp = zeros(cols*rows,1);
tmp(1:samples) = a;
% reshape the data
b = reshape(tmp,cols,rows);
% flip dimensions
c = b'
c = 5×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 0

Tags

Community Treasure Hunt

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

Start Hunting!