Problem extracting values from for loop

36 views (last 30 days)
Michael
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
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

Sign in to comment.

Accepted Answer

Image Analyst
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);
  1 Comment
Michael
Michael on 26 Apr 2025 at 18:19
Yes this worked thank you, and yes i forgot to mention that the passband_frequencies was also a vector

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!