Rearrange matrix and concatenate cells
1 view (last 30 days)
Show older comments
Hi everyone,
I have a 3492x5 matrix with variable names say variable1, variable2,...,variable5. I have been trying to cut this matrix into 12 291x5 cells and rearrange them into a 291x60 matrix. But when I did this, I had error of duplicate variable names. So, I'm wondering if there way to circumvent this? With or without variable names is ok for me since they are not really useful.
Here is the code I used:
filename=datadimer
[m n]=size(filename)
sZ=291;
Numofrows= m/(sZ);
C=mat2cell(filename,sZ*ones(1,Numofrows),size(filename,2));
for i=1:Numofrows
D(:,i)=C(i,:);
end
output=horzcat(D{:});
The input matrix ('filename') contains one row of string and first 16 rows look like this:
Any help will be much appreciated, thank you!
1 Comment
Walter Roberson
on 21 Apr 2019
Could you confirm that your variable filename, rather than being the name of a file, is a cell array of character vectors, one cell per input line? How is the split header ("centered 1, linebreak, centered Variable1") encoded in the character vector? Is there any delimiter between the numeric entries, such as comma, or are they fixed width?
Answers (1)
Andrei Bobrov
on 21 Apr 2019
If your datadimer is table:
A = datadimer{:,:};
sZ = 291;
[m,n] = size(A);
k = m/sZ;
out = reshape(permute(reshape(A,sZ,k,n),[3,1,2]),sZ,[]);
0 Comments
See Also
Categories
Find more on Cell Arrays 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!