Non Compatible Indices, Combining array sections

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

 채택된 답변

Steven Lord
Steven Lord 2020년 10월 18일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2020년 10월 18일

댓글:

2020년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by