Problem extracting values from for loop

3 ビュー (過去 30 日間)
Michael
Michael 2025 年 4 月 26 日
コメント済み: Stephen23 2025 年 4 月 26 日
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 件のコメント
Stephen23
Stephen23 2025 年 4 月 26 日
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

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2025 年 4 月 26 日
編集済み: Image Analyst 2025 年 4 月 26 日
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 件のコメント
Michael
Michael 2025 年 4 月 26 日
Yes this worked thank you, and yes i forgot to mention that the passband_frequencies was also a vector

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by