'Matlab cell to matrix vectorization
I have a cell with 3 synchronized signals in each column. I want to extract specific segments into my seg cell. How do I get rid of the loop here?
data = cell(1, 3);
data{1,1} = [ones(30, 1)];
data{1,2} = [1:30]';
data{1,3} = 2*[1:30]';
ind1 = [1; 11; 17];
ind2 = [10; 16; 30];
for i = 1:3
seg{i, 1} = [data{:,1}(ind1(i):ind2(i)) data{:,2}(ind1(i):ind2(i)) data{:,3}(ind1(i):ind2(i))];
end
Solution 1:[1]
You mean like this?
data = cell(1, 3);
data{1,1} = ones(30, 1);
data{1,2} = (1:30)';
data{1,3} = 2*(1:30)';
D = cell2mat(data);
Cel = mat2cell(D,[10 6 14],3);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AboAmmar |
