Non Compatible Indices, Combining array sections
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zachary Kober
el 18 de Oct. de 2020
Comentada: Zachary Kober
el 18 de Oct. de 2020
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 comentarios
Respuesta aceptada
Steven Lord
el 18 de Oct. de 2020
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!