Build an array with different column lengths
Mostra commenti meno recenti
Have one large data set (3333x1 double) and am trying to section out rows based on certain index values. If I have say 10 index pairs (beginning and end row) that I want to section out,each with different lengths how can I build one new nx10 matrix?
I keep getting subscripted assignment mismatches and similar errors when I try things like:
for i = 1:length(indices)
newData(:,i) = olddata(indexstart(i):indexstop(i),:);
end
Risposte (1)
Usually you would store such a result as a cell array,
newData=cell(1, length(indices));
for i = 1:length(indices)
newData{i} = olddata(indexstart(i):indexstop(i));
end
If it needs to be a numeric array, you need to decide what will go in the missing spots.
4 Commenti
matlabuser12
il 15 Ago 2016
SO this will give me one cell array with multiple columns? or multiple cells each with a column in it?
Both. A cell array consists of multiple cells. In this case, the cell array that gets created is 1xlength(indices). In other words, it has N=length(indices) columns.
The content of each of the N cells is a numeric vector from olddata. It will be a numeric column vector if your olddata was also a column vector.
matlabuser12
il 15 Ago 2016
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!