How can I fix the warning and the error in parfor?
Ältere Kommentare anzeigen
a = linspace(1,100,100);
parfor i=1:10
for j=1:10
k = (i-1)*10+j;
b = a(k)+5; %// warning
c(k) = b; %// error
end
end
How can I fix the warning about a(k) and the error about c(k)?
5 Kommentare
Dyuman Joshi
am 26 Mär. 2024
Verschoben: Dyuman Joshi
am 26 Mär. 2024
Why are you using parfor for this?
Simply use a for loop -
a = linspace(1,100,100);
for i=1:10
for j=1:10
k = (i-1)*10+j;
b = a(k)+5; %// warning
c(k) = b; %// error
end
end
c
Jingtao
am 26 Mär. 2024
Verschoben: Dyuman Joshi
am 26 Mär. 2024
Jingtao
am 26 Mär. 2024
a = linspace(1,100,100);
k = 1;
parfor i=1:10
for j=1:10
c(i,j) = a((i-1)*10+j)+5; %// error
end
end
c = reshape(c,1,[]) % do reshape after the loop computation
Dyuman Joshi
am 26 Mär. 2024
Bearbeitet: Dyuman Joshi
am 26 Mär. 2024
"This is a simplified code for demonstration. Actually number of the loops is huge."
In that case, please share your original code and specify what the objective is.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!