Clear Filters
Clear Filters

How to convert single column into multiple column having different spacing

8 views (last 30 days)
Hi, I have a data file which is quite big, I want to reshape my data file but problem is that my data point is not uniformly spaced. For example, in this case, I want to have 1500 rows and 300 columns and each column must start from different temperature as in the first column of the raw file.
M = dlmread('MHfinal.dat', '', 2, 0); %%2, 0 represent from you want to start.
M1 = reshape(M,1542,7);

Accepted Answer

Walter Roberson
Walter Roberson on 29 Oct 2018
uniquetol() applied to the temperature column. The third output is the grouping variable. Use
Output = accumarray(TheGroupingVariable, ThirdColumn, [], @(v){v.'});
If the resulting cell array happens to have the same number of entries in each cell then cell2mat. But it looks to me as if that is not likely to be the case: it looks to me as if your first temperatures do not repeat.
  10 Comments
Walter Roberson
Walter Roberson on 2 Nov 2018
Do you want separate variables
Output_1 = [Output2(:,1), Output3(:,1)];
Output_2 = [Output2(:,2), Output3(:,2)];
Output_3 = [Output2(:,3), Output3(:,3)];
...
Output_7 = [Output2(:,7), Output3(:,7)];
Or do you want a single array,
Output = [Output2(:,1), Output3(:,1), Output2(:,2), Output3(:,2), Output2(:,3), Output3(:,3), ... Output2(:,7), Output3(:,7)];
The code I posted for combined builds the second of those possibilities.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!