Problem extracting values from for loop
36 views (last 30 days)
Show older comments
Michael
on 26 Apr 2025 at 17:41
Commented: Stephen23
on 26 Apr 2025 at 19:14
F = getdatasamples(y_out.clean,[1:567]);
A = getdatasamples(y_out.simout,[1:567]);
figure(2)
hold on
[RMSE] = rmse(F,A);
plot(passband_frequencies,RMSE)
this is within a forloop and I want to get individual RMSE values for each iteration to plot them against anouther varible I have but I am not sure how to do it
1 Comment
Stephen23
on 26 Apr 2025 at 19:14
Note that square brackets are a concatenation operator. The colon returns a vector, which you then concatenate with ... absolutely nothing (which what the orange mlint warning is telling you). So instead of this
[1:567]
you just need
1:567
Accepted Answer
Image Analyst
on 26 Apr 2025 at 18:02
Edited: Image Analyst
on 26 Apr 2025 at 18:05
Index the RMSE variable:
for loopIndex = 1 : whatever
F = getdatasamples(y_out.clean, [1:567]);
A = getdatasamples(y_out.simout, [1:567]);
figure(2, 'Name', 'RMSE');
hold on
RMSE(loopIndex) = rmse(F, A);
% Plot (add) a single marker.
plot(passband_frequencies, RMSE(loopIndex), 'b.', 'MarkerSize', 30);
end
hold off;
% Plot the whole array
plot(passband_frequencies, RMSE, 'b-', 'LineWidth', 3);
grid on;
xlabel('Passband Frequency');
ylabel('RMSE')
I'm not sure what passband_frequencies is (scalar or vector of some length) so you might have to index that inside the loop as well, like
plot(passband_frequencies(loopIndex), RMSE(loopIndex), 'b.', 'MarkerSize', 30);
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!