MATLAB: How to control color inside a for loop

MATLABmatlab function

Hello, this is a follow up to this question.
I asked if it is possible to control the color used by graphs plotted by a for loop.
Ameer Hamza's answer made it possible to controll the color used by both the plotting of the data points (if no errorbars are plotted, as well as of the errorbars.
However, I can't figure out how to implement this for the plotting of the fits themselves. The fits are still using random colors, and not those specified. If I try to apply Hamza's solution to the plotted fits, I am greeted with
>> LPplotfun(LPmatx,LPmaty,LPFits,LPNumRows,LPErrorbarflag,LPplottypeindx)
Error using cfit/plot>parseinput (line 332)
Must specify both XDATA and YDATA.
Error in cfit/plot (line 46)
[S1,xdata,ydata,S2,outliers,S3,ptypes,conflev] = parseinput(alltypes,varargin);
Error in LPplotfun (line 11)
plot(LPFits{1,k},'Color',colors(rem(k-1,3)+1,:)) % the user adjusts the axes himself.
All of the above are error outputs from the command window.
This is the code for the plotting of the fits, but not the complete function.
function LPplotfun(LPmatx,LPmaty,LPFits,LPNumRows,LPErrorbarflag,LPplottypeindx)
colors = [1 0 0; % red
0 0 1; % blue
0 1 0;]; % green
if LPplottypeindx==1 % Line plot
for k=1:1:LPNumRows
hold on
axis([-500 500 -500 500]) % this line controls the area in which the graphs are plotted initially, before the user adjust them himself later on
plot(LPFits{1,k},'') % Set axis to higher values if you want to see more before adjusting the axes yourself.
%plot(LPFits{1,k},'Color',colors(rem(k-1,3)+1,:))
hold on
if LPErrorbarflag==0
plot(LPmatx(k,:),LPmaty(k,:),'o','Color',colors(rem(k-1,3)+1,:))
hold on
else
hold on
end % LPfits=LPfitfun(LPmatx,LPmaty,LPNumRows) %"LPfits" is the name of the cell in which all LPfits are stored.
hold on
end
end
end
This is not the entire code of the function, but all that is necessary. Technically the function can also plot bar plots and other ones, but this is not what I am concerned with right now. If needed, I can provide the full function. This is also why the variable "LPplottypeindx" is not used in this part. All that is missing is using the LPplottypeindx to control which part of the whole function is run. (In case of normal line plots it's the code shown above.)
The line "%plot(LPFits{1,k},'Color',colors(rem(k-1,3)+1,:))" is what I tried to get working, and what is causing the error messages shown above.
Thank you once again.
Note: Technically I am running Matlab R2020a now, but I checked and the same problem persists in R2019b. However, since I cannot yet choose R2020a as my used Release version, I chose R2019b.

Best Answer

I haven't dug too deeply into the two threads but I think this will work for you. If not, I'll remove the answer so the question isn't marked as answered.
h = plot(LPFits{1,k});
h.Color = colors(rem(k-1,3)+1,:);