switch in a loop while changing variable name according to iter index

3 ビュー (過去 30 日間)
fadams18
fadams18 2018 年 10 月 19 日
編集済み: Fangjun Jiang 2018 年 10 月 19 日
I have the following
id =1;
Switch id
case 1
Data_1=[mean_RSI_high,mean_RSI_low,mean_NeNMF_high,mean_NeNMF_low];
case 2
Data_2=[mean_RSI_high,mean_RSI_low,mean_NeNMF_high,mean_NeNMF_low];
.
.
.
Case 60
end
I have to switch throught to case 60. How can i do this in a loop

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 10 月 19 日
construct your data as 60xn matrix
Data(1,:)=[mean_RSI_high,mean_RSI_low,mean_NeNMF_high,mean_NeNMF_low];
...
Data(60,:)=[...];
then you can do index, instead of using Switch statement with 60 cases.
Data(id,:)
  2 件のコメント
fadams18
fadams18 2018 年 10 月 19 日
that is still a lot. its actually 60 x12. and the text becomes to clumsy. insnt there a way to assign
[mean_RSI_high,mean_RSI_low,mean_NeNMF_high,mean_NeNMF_low]
to a variable say Data(1,:)=var. But then if i do it this way my values will be in var which will inturn be in Data. but i dont want that. I want the values to be directly in Data, when i click it
Fangjun Jiang
Fangjun Jiang 2018 年 10 月 19 日
編集済み: Fangjun Jiang 2018 年 10 月 19 日
I don't get it. You need to get 60 values for 60 scenarios. If the value for each scenario is slightly different, then you need to construct them in a manual fashion in any cases. If the value for most scenarios is the same, then you can use other ways to construct it, such as repmat(). My advice here is not to use switch-case to find the value for your scenario. Rather, use indexing.

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

その他の回答 (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