Non Compatible Indices, Combining array sections

7 ビュー (過去 30 日間)
Zachary Kober
Zachary Kober 2020 年 10 月 18 日
コメント済み: Zachary Kober 2020 年 10 月 18 日
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 日
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
  1 件のコメント
Zachary Kober
Zachary Kober 2020 年 10 月 18 日
Thank you for the suggestion!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by