Use the index in a FOR loop for a string

How do I make 50 plots (in separate figures) using the following format:
for i = 1:50
figure('name','Hurricane "i"')
scatter(x,y,10,z"i");
title('Hurricane "i"');
end
e.g. I want graphs like scatter(x,y,10,z36) with the title of "Hurricane 36". Thanks for your help in advance.

 採用された回答

Stephen23
Stephen23 2017 年 4 月 11 日

0 投票

@Mamali: you should put your data into one array (either an matrix, and ND array, or a cell array) and using indexing. Do not try to access variable names dynamically:

その他の回答 (1 件)

John Osborne
John Osborne 2017 年 4 月 10 日
編集済み: John Osborne 2017 年 4 月 10 日

0 投票

Try
figure(i)
%plotting commands
title(['Hurricane ' num2str(i)])

3 件のコメント

Antonio
Antonio 2017 年 4 月 10 日
Tnx, but how do you determine z"i" in plotting commands? like z1, z2, ... z50?
Stephen23
Stephen23 2017 年 4 月 11 日
編集済み: Stephen23 2017 年 4 月 11 日
@Mamali: you should put your data into one array (either an matrix, and ND array, or a cell array) and using indexing. Do not try to access variable names dynamically:
Antonio
Antonio 2017 年 4 月 11 日
@Stephen Cobeldick: Thanks for your great answer :)

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2017 年 4 月 10 日

回答済み:

2017 年 4 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by