How can I remove the error "unable to perform because the indices on the left side are not compatible with the size of the right side"

1 visualización (últimos 30 días)
Hi,
I am trying to run a for loop but it shows me this error "Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side".
The line is error-free when I am running the line without loop. But I need a loop because by replication number here can be 5000.
How can I remove this error?
replication=10;
signal_resolution_merge=2;
for i= 1:replication
Output(i) = sum(reshape(Final_result.nRx_raw_matrix_wout_noise(:,:,(i)), ...
signal_resolution_merge, size(Final_result.nRx_avg,2)/signal_resolution_merge));
end
The above code is showing error, but following code is erro-free for any number (1 to 10),
Output = sum(reshape(Final_result.nRx_raw_matrix_wout_noise(:,:,1), ...
signal_resolution_merge, size(Final_result.nRx_avg,2)/signal_resolution_merge));
I want to store output values for each replication.
Thank you for your time and considerations.

Respuesta aceptada

Tommy
Tommy el 27 de Mayo de 2020
It seems like you are calling sum on 2D arrays, so each output would be a row vector, which you can't store within Output(i). You could instead store the vectors in a cell array:
replication=10;
signal_resolution_merge=2;
Output = cell(replication,1);
for i= 1:replication
Output{i} = sum(reshape(Final_result.nRx_raw_matrix_wout_noise(:,:,(i)), ...
signal_resolution_merge, size(Final_result.nRx_avg,2)/signal_resolution_merge));
end
or, if you'd like, a matrix (Output(i,:) = sum(...)).

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by