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"
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tania Islam
am 27 Mai 2020
Kommentiert: Tania Islam
am 27 Mai 2020
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 Kommentare
Akzeptierte Antwort
Tommy
am 27 Mai 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(...)).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!