Problem extracting values from for loop

3 Ansichten (letzte 30 Tage)
Michael
Michael am 26 Apr. 2025
Kommentiert: Stephen23 am 26 Apr. 2025
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 Kommentar
Stephen23
Stephen23 am 26 Apr. 2025
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 26 Apr. 2025
Bearbeitet: Image Analyst am 26 Apr. 2025
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 Kommentar
Michael
Michael am 26 Apr. 2025
Yes this worked thank you, and yes i forgot to mention that the passband_frequencies was also a vector

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing 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!

Translated by