Non Compatible Indices, Combining array sections
7 次查看(过去 30 天)
显示 更早的评论
Hi All,
I am trying to pull certain elements from a large 1x30000 double (Say P) to create a smaller 1x3600 double (Say H). I am currently getting an error "Unable to perform assignment because the indices on the left side are not compatiblewith the size of the right side." I am guessing that is because what I have written is not adding the different k values together and is getting stuck at k=1. Any help would be much appreciated.
n=60;
Res=5;
S=1640;
for k = 1:n
H(k) = (P((S+((k-1)*48*Res)):(S+(12*Res)+((k-1)*(48*Res)))));
end
0 个评论
采纳的回答
Steven Lord
2020-10-18
You can't put multiple numbers into one element of a numeric array.
x = 1:10;
x(5) = ... % assigning to one element of x
[99 4]; % and trying to store two elements into it won't fit
You could use a cell array, or you could assign to a segment of the array large enough to fit the data you're trying to store in it.
C = cell(1, 10);
C{5} = ... % Note I'm using curly braces to assign to the contents of the fifth cell
[99 4]; % rather than assigning to the fifth cell itself.
% or
y = zeros(2);
y(1, :) = ... % Referring to all two columns in the first row of y
[99, 4]; % This has one row and two columns, the same size as the target of the assignment
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!