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 次查看(过去 30 天)
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.

采纳的回答

Tommy
Tommy 2020-5-27
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(...)).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by