フィルターのクリア

Use num2str in for loop

5 ビュー (過去 30 日間)
Mac
Mac 2023 年 10 月 29 日
コメント済み: Mac 2023 年 10 月 29 日
Good day. I know is simple but I can't find the solution to this. I want to call some data (M3 to M11) in for loop using num2str, but it does not work. Below is the code, specifically in bold.
M3 = mean(Mar, 3);
M4 = mean(Apr, 3);
M5 = mean(May, 3);
M6 = mean(Jun, 3);
M7 = mean(Jul, 3);
M8 = mean(Aug, 3);
M9 = mean(Sep, 3);
M10 = mean(Oct, 3);
M11 = mean(Nov, 3);
[xx,yy]=meshgrid(lon,lat);
b=-18:2:18;
f = figure;
t = tiledlayout(f, 3, 3);
for i = 3:11
nexttile(t)
m_proj('miller','lon',[110 130],'lat',[0 15]);
m_contourf(xx,yy,['M', num2str(i)], b,'linestyle','none');
colormap(m_colmap('BOD',256))
................
  12 件のコメント
Stephen23
Stephen23 2023 年 10 月 29 日
Mac
Mac 2023 年 10 月 29 日
Thanks @Stephen23. Appreciate it.

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

採用された回答

Walter Roberson
Walter Roberson 2023 年 10 月 29 日
Please read http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval for information about why we strongly recommend against creating variable names dynamically.
M3 = mean(Mar, 3);
M4 = mean(Apr, 3);
M5 = mean(May, 3);
M6 = mean(Jun, 3);
M7 = mean(Jul, 3);
M8 = mean(Aug, 3);
M9 = mean(Sep, 3);
M10 = mean(Oct, 3);
M11 = mean(Nov, 3);
M = {[], [], M3, M4, M5, M6, M7, M8, M9, M10, M11}; %two dummy so M{i} corresponds to M_i
for i = 3:11
nexttile(t)
m_proj('miller','lon',[110 130],'lat',[0 15]);
m_contourf(xx,yy,M{i}, b,'linestyle','none');
colormap(m_colmap('BOD',256))
  1 件のコメント
Mac
Mac 2023 年 10 月 29 日
Thanks a lot Walter. Noted. Thank to both for the enlightenment.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by