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.
댓글 수: 0
채택된 답변
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!